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
@@ -31,14 +31,23 @@ const tipsyTenant = `(env) => {
|
||||
return 'mowed 20 cells';
|
||||
}`;
|
||||
|
||||
/** `{ a, b: { c } }`: keys, and the keys of object-valued members */
|
||||
const shape = (record: Readonly<Record<string, unknown>>) =>
|
||||
/** diagram-local names, bound by the reply arrows that introduce them */
|
||||
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)
|
||||
.map(([key, value]) =>
|
||||
value !== null && typeof value === 'object' && !Array.isArray(value)
|
||||
? `${key}: { ${Object.keys(value).join(', ')} }`
|
||||
: key,
|
||||
)
|
||||
.map(([key, value]) => {
|
||||
if (value === null || typeof value !== 'object') return key;
|
||||
const name = local.get(value);
|
||||
if (name) return `${key}: ${name}`;
|
||||
return Array.isArray(value) ? key : `${key}: ${shape(value)}`;
|
||||
})
|
||||
.join(', ')} }`;
|
||||
|
||||
const quoted = (result: unknown) => `'${String(result)}'`;
|
||||
@@ -50,19 +59,22 @@ const viz = harden({
|
||||
return `lend({ webkey: '${webkey}', limit: ${limit}, say })`;
|
||||
},
|
||||
},
|
||||
mower: { result: () => 'mower' },
|
||||
govern: { args: args => `mower, ${String(args[1])}`, result: () => 'governed' },
|
||||
mower: { result: bind('mower') },
|
||||
govern: {
|
||||
args: args => `${local.get(args[0] as object)}, ${String(args[1])}`,
|
||||
result: bind('governed'),
|
||||
},
|
||||
chat: {
|
||||
label: args => `chat(${shape(args[0] as Record<string, unknown>)})`,
|
||||
label: args => `chat(${shape(args[0] as object)})`,
|
||||
result: quoted,
|
||||
},
|
||||
complete: {
|
||||
label: args =>
|
||||
`complete([${(args[0] as Record<string, unknown>[]).map(shape).join(', ')}])`,
|
||||
`complete([${(args[0] as object[]).map(shape).join(', ')}])`,
|
||||
result: () => 'code',
|
||||
},
|
||||
load: {
|
||||
args: args => `code, { ${Object.keys(args[1] as object).join(', ')} }`,
|
||||
args: args => `code, ${shape(args[1] as object)}`,
|
||||
result: () => 'tenant',
|
||||
},
|
||||
run: { result: quoted },
|
||||
|
||||
Reference in new issue
Block a user