test(good-fences): show which mower the neighbor gets
The chat and load arrows drew `things: { mower }` whether I lent the
raw mower or the governed one. Name objects by the reply arrow that
introduced them, so the diagram reads `things: { mower: governed }`
and lending the raw mower would fail the trace comparison.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
9a3e7348c6
commit
9b12943be4
2 files changed
+27
-15
No files matched your search
@@ -38,10 +38,10 @@ sequenceDiagram
|
|||||||
MF-->>F: mower
|
MF-->>F: mower
|
||||||
F-->>P: govern(mower, 2)
|
F-->>P: govern(mower, 2)
|
||||||
P-->>F: governed
|
P-->>F: governed
|
||||||
F-->>N: chat({ role, content, things: { mower }, about: { mower } })
|
F-->>N: chat({ role, content, things: { mower: governed }, about: { mower: { ts } } })
|
||||||
N-->>L: complete([{ role, content, about: { mower } }])
|
N-->>L: complete([{ role, content, about: { mower: { ts } } }])
|
||||||
L-->>N: code
|
L-->>N: code
|
||||||
N-->>TL: load(code, { mower })
|
N-->>TL: load(code, { mower: governed })
|
||||||
TL-->>N: tenant
|
TL-->>N: tenant
|
||||||
N-->>T: run()
|
N-->>T: run()
|
||||||
T-->>G: start()
|
T-->>G: start()
|
||||||
|
|||||||
@@ -31,14 +31,23 @@ const tipsyTenant = `(env) => {
|
|||||||
return 'mowed 20 cells';
|
return 'mowed 20 cells';
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
/** `{ a, b: { c } }`: keys, and the keys of object-valued members */
|
/** diagram-local names, bound by the reply arrows that introduce them */
|
||||||
const shape = (record: Readonly<Record<string, unknown>>) =>
|
const local = new WeakMap<object, string>();
|
||||||
|
const bind = (name: string) => (result: unknown) => {
|
||||||
|
local.set(result as object, name);
|
||||||
|
return name;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** `{ a, b: { c: governed } }`: keys, nested objects by their keys, and
|
||||||
|
* objects with a diagram-local name by that name */
|
||||||
|
const shape = (record: object): string =>
|
||||||
`{ ${Object.entries(record)
|
`{ ${Object.entries(record)
|
||||||
.map(([key, value]) =>
|
.map(([key, value]) => {
|
||||||
value !== null && typeof value === 'object' && !Array.isArray(value)
|
if (value === null || typeof value !== 'object') return key;
|
||||||
? `${key}: { ${Object.keys(value).join(', ')} }`
|
const name = local.get(value);
|
||||||
: key,
|
if (name) return `${key}: ${name}`;
|
||||||
)
|
return Array.isArray(value) ? key : `${key}: ${shape(value)}`;
|
||||||
|
})
|
||||||
.join(', ')} }`;
|
.join(', ')} }`;
|
||||||
|
|
||||||
const quoted = (result: unknown) => `'${String(result)}'`;
|
const quoted = (result: unknown) => `'${String(result)}'`;
|
||||||
@@ -50,19 +59,22 @@ const viz = harden({
|
|||||||
return `lend({ webkey: '${webkey}', limit: ${limit}, say })`;
|
return `lend({ webkey: '${webkey}', limit: ${limit}, say })`;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mower: { result: () => 'mower' },
|
mower: { result: bind('mower') },
|
||||||
govern: { args: args => `mower, ${String(args[1])}`, result: () => 'governed' },
|
govern: {
|
||||||
|
args: args => `${local.get(args[0] as object)}, ${String(args[1])}`,
|
||||||
|
result: bind('governed'),
|
||||||
|
},
|
||||||
chat: {
|
chat: {
|
||||||
label: args => `chat(${shape(args[0] as Record<string, unknown>)})`,
|
label: args => `chat(${shape(args[0] as object)})`,
|
||||||
result: quoted,
|
result: quoted,
|
||||||
},
|
},
|
||||||
complete: {
|
complete: {
|
||||||
label: args =>
|
label: args =>
|
||||||
`complete([${(args[0] as Record<string, unknown>[]).map(shape).join(', ')}])`,
|
`complete([${(args[0] as object[]).map(shape).join(', ')}])`,
|
||||||
result: () => 'code',
|
result: () => 'code',
|
||||||
},
|
},
|
||||||
load: {
|
load: {
|
||||||
args: args => `code, { ${Object.keys(args[1] as object).join(', ')} }`,
|
args: args => `code, ${shape(args[1] as object)}`,
|
||||||
result: () => 'tenant',
|
result: () => 'tenant',
|
||||||
},
|
},
|
||||||
run: { result: quoted },
|
run: { result: quoted },
|
||||||
|
|||||||
Reference in new issue
Block a user