Skip to content

Commit 809cbc2

Browse files
thymikeeclaude
andcommitted
test(snapshot): assert every scoped ref is pinned, and note the --raw exception
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 2711b31 commit 809cbc2

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

‎packages/command-output/src/capture/output.test.ts‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ const REPEATED_CHAIN: RawSnapshotNode[] = [
4444
},
4545
];
4646

47+
const SCOPED_SUBTREE: RawSnapshotNode[] = [
48+
{ index: 0, type: 'Other', label: 'Checkout', depth: 0 },
49+
{ index: 1, type: 'Button', label: 'Pay now', depth: 1, parentIndex: 0 },
50+
{ index: 2, type: 'TextField', label: 'Card number', depth: 1, parentIndex: 0 },
51+
];
52+
4753
test('default (non-raw) output dedups repeated ancestor labels in both text and json', async () => {
4854
const output = await snapshotCliOutput({ result: buildResult(REPEATED_CHAIN) });
4955

@@ -218,15 +224,23 @@ test('settings renders response warnings after the message', async () => {
218224
// through the production ref grammar to the same node and refs generation.
219225
test('--scope output prints refs a caller can paste back as the same ref and generation', async () => {
220226
const output = await snapshotCliOutput({
221-
result: { ...buildResult(REPEATED_CHAIN.slice(0, 1)), refsGeneration: 752890 },
227+
result: { ...buildResult(SCOPED_SUBTREE), refsGeneration: 752890 },
222228
scope: '@e1',
223229
});
224230

225-
const pin = /(@e\d+~s\d+) \[/.exec(output.text!)?.[1];
226-
assert.equal(pin, '@e1~s752890');
227-
assert.deepEqual(splitRefGenerationSuffix(pin!), { base: '@e1', generation: 752890 });
228-
assert.equal(normalizeRef(pin!), 'e1');
229-
assert.equal((output.jsonData as { nodes: Array<{ ref: string }> }).nodes[0]!.ref, 'e1');
231+
const printed = [...output.text!.matchAll(/@e\d+\S*/g)].map((match) => match[0]);
232+
const jsonRefs = (output.jsonData as { nodes: Array<{ ref: string }> }).nodes.map(
233+
(node) => node.ref,
234+
);
235+
assert.deepEqual(jsonRefs, ['e1', 'e2', 'e3']);
236+
assert.deepEqual(printed, ['@e1~s752890', '@e2~s752890', '@e3~s752890']);
237+
for (const [i, pin] of printed.entries()) {
238+
assert.deepEqual(splitRefGenerationSuffix(pin), {
239+
base: `@${jsonRefs[i]}`,
240+
generation: 752890,
241+
});
242+
assert.equal(normalizeRef(pin), jsonRefs[i]);
243+
}
230244
});
231245

232246
test('output without --scope keeps plain refs even when a refs generation is present', async () => {

‎packages/kernel/src/snapshot.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,8 @@ export function snapshotRefMinting(
931931
* `~s<generation>` suffix pinning it to the session snapshot generation that
932932
* minted it, e.g. `@e12~s3`. Snapshot output stays plain `e12` refs (the tree is
933933
* the most token-expensive artifact agents consume), except the CLI text of a
934-
* `--scope` snapshot, which prints every ref in this pinned form (ADR 0014).
934+
* `--scope` snapshot, which prints every ref in this pinned form unless `--raw`
935+
* is set (ADR 0014).
935936
* Ref-issuing responses carry the generation ONCE as the additive
936937
* `refsGeneration` field.
937938
*/

0 commit comments

Comments
 (0)