返回 CodeWhale
pet-forms.test.mjs
根目录 / pet / tests / pet-forms.test.mjs
1 import test from 'node:test';
2 import assert from 'node:assert/strict';
3 import { projectDotField } from '../dist/core/dot-field.js';
4 import { getFormLayout } from '../dist/core/dot-forms.js';
5
6 const KINDS = ['reading', 'editing', 'searching', 'testing', 'executing', 'browsing', 'computer', 'memory',
7 'tool', 'thinking', 'responding', 'delegating'];
8 const activity = (verb, extra = {}) => ({ sessionId: 's', cursor: 1, observed: true, freshness: 'fresh',
9 authoritativePresence: verb === 'waiting' ? 'needs_you' : verb === 'done' ? 'done' : 'working',
10 activityKind: ['waiting', 'done'].includes(verb) ? null : verb, observedAtMs: 0, parallelAgentCount: 3,
11 activeSpans: [], turnId: 't', turnOutcome: null, doneEffectId: verb === 'done' ? 't' : null, failedToolAge: null, ...extra });
12 const whale = (style) => projectDotField(activity('reading', { observed: false, freshness: 'missing' }), 0, true, 0, { bodyStyle: style });
13 const inside = (field) => field.points.length === 980 && field.materials.length === 980
14 && field.points.every(p => p.every(v => Number.isFinite(v) && Math.abs(v) <= .94))
15 && field.materials.every(m => m.length === 4 && m.every(Number.isFinite) && m[3] >= 0 && m[3] <= 1);
16
17 test('every activity forms its own moving shape from all 980 dots, deterministically, and returns to the whale', () => {
18 for (const style of ['smooth', 'pixel']) {
19 const home = whale(style);
20 assert.equal(home.morph, 0);
21 for (const verb of [...KINDS, 'waiting', 'done']) {
22 const at = verb === 'done' ? [300, 600] : [3000, 4000];
23 const formed = projectDotField(activity(verb), at[0], false, 0, { bodyStyle: style });
24 assert.ok(inside(formed) && formed.morph === 1 && formed.bodyStyle === style, `${style} ${verb}`);
25 assert.deepEqual(projectDotField(activity(verb), at[0], false, 0, { bodyStyle: style }), formed);
26 assert.notDeepEqual(projectDotField(activity(verb), at[1], false, 0, { bodyStyle: style }).points, formed.points, `${verb} moves`);
27 const still = projectDotField(activity(verb), at[0], true, 0, { bodyStyle: style });
28 assert.ok(inside(still) && still.morph === 1);
29 assert.deepEqual(projectDotField(activity(verb), at[1], true, 0, { bodyStyle: style }), still, `${verb} still is fixed`);
30 assert.notDeepEqual(still.points, home.points);
31 const settled = verb === 'done' ? 2600 : 5500;
32 assert.equal(projectDotField(activity(verb), settled, false, 0, { bodyStyle: style }).morph, 0, `${verb} returns home`);
33 }
34 }
35 assert.deepEqual(projectDotField(activity('tool'), 3000, true).points, projectDotField(activity('executing'), 3000, true).points);
36 assert.notDeepEqual(projectDotField(activity('delegating', { parallelAgentCount: 2 }), 3000, true).points,
37 projectDotField(activity('delegating'), 3000, true).points);
38 for (const unobserved of [{ observed: false }, { freshness: 'stale' }, { authoritativePresence: 'idle' }])
39 assert.equal(projectDotField(activity('reading', unobserved), 3000, false).morph, 0);
40 });
41
42 test('compiled hex-lattice forms preserve 0.32 * pitch dot separation and bounds across styles', () => {
43 const forms = [...KINDS.filter(k => k !== 'tool'), 'waiting', 'done'];
44 for (const style of ['smooth', 'pixel']) {
45 for (const kind of forms) {
46 for (const agents of kind === 'delegating' ? [2, 3] : [3]) {
47 const { pitch, slots } = getFormLayout(kind, style, agents);
48 assert.equal(slots.length, 980, `${style} ${kind}`);
49 assert.ok(pitch > 0.01 && pitch < 0.1, `${style} ${kind} pitch=${pitch}`);
50 const radius = 0.32 * pitch;
51 const minSeparation = 2 * radius;
52 const unique = [];
53 for (const slot of slots) {
54 assert.ok(Math.abs(slot.x) <= 0.94 - radius * 0.5 && Math.abs(slot.y) <= 0.94 - radius * 0.5, `${style} ${kind} out of bounds`);
55 if (!unique.some(u => u.x === slot.x && u.y === slot.y)) unique.push(slot);
56 }
57 for (let i = 0; i < unique.length; i++) {
58 for (let j = i + 1; j < unique.length; j++) {
59 const d = Math.hypot(unique[i].x - unique[j].x, unique[i].y - unique[j].y);
60 assert.ok(d >= minSeparation, `${style} ${kind} dots overlap: ${d} < ${minSeparation}`);
61 }
62 }
63 }
64 }
65 }
66 });
67
67 lines Plain Text