mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-02 15:04:37 +01:00
fix: journal reader skips a failed or unreadable init, as invocation() does
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
bdac971bc6
commit
532c0f374c
2 files changed
+9
-4
No files matched your search
@@ -74,10 +74,12 @@ function select(tests: GuardJournalTests, currentToolUseId: string) {
|
||||
.filter(e => e.kind === 'result' && e.toolUseId === init.use.toolUseId && e.order > init.use.order);
|
||||
let reply: unknown;
|
||||
try { reply = replies.length === 1 ? bashJson(textResult(replies[0]!) ?? 'null') : undefined; } catch { reply = undefined; }
|
||||
// A failed or unreadable init binds nothing and is skipped, as invocation() does.
|
||||
if (!object(reply)) continue;
|
||||
// A reused:true init keeps the earlier binding, as invocation() does.
|
||||
if (object(reply) && reply.reused === true && bound && bound.activePlan === reply.activePlan &&
|
||||
bound.restorePath === reply.restorePath) continue;
|
||||
chainStart = init.record; bound = object(reply) ? reply : undefined;
|
||||
chainStart = init.record; bound = reply;
|
||||
}
|
||||
let start = 0;
|
||||
for (let i = chainStart ?? records.length - 1; i >= 0; i--)
|
||||
|
||||
@@ -1628,14 +1628,15 @@ describe('#3651: Claude Code cwd-reset footer on a Bash result', () => {
|
||||
expect(decision.reason).toContain('re-run');
|
||||
});
|
||||
|
||||
test('#3651: the hook path keeps the first binding when a cwd-reset init is re-run after a typed user message', async () => {
|
||||
test('#3651: the hook path keeps the first binding when an init is re-run after a typed user message', async () => {
|
||||
const footer = '\nShell cwd was reset to /home/user/project';
|
||||
const run = async (tail: string) => {
|
||||
const run = async (tail: string, failed?: unknown) => {
|
||||
const f = fixture(); (f.events[1] as any).content += tail; f.message();
|
||||
if (failed !== undefined) { f.use('bad-init', 'Bash', (f.events[0] as any).input); f.result('bad-init', { content: failed }); }
|
||||
f.use('re-init', 'Bash', (f.events[0] as any).input); f.result('re-init', { content: JSON.stringify({ ...f.init, reused: true }) + tail });
|
||||
f.current();
|
||||
const { rows, record } = f.journal();
|
||||
const at = rows.findIndex(r => Array.isArray(r.message.content) && r.message.content.some((b: any) => b.type === 'tool_use' && b.id === 're-init'));
|
||||
const at = rows.findIndex(r => Array.isArray(r.message.content) && r.message.content.some((b: any) => b.type === 'tool_use' && ['bad-init', 're-init'].includes(b.id)));
|
||||
rows[at - 1]!.message.stop_reason = 'end_turn';
|
||||
rows.splice(at, 0, record('user', 'Looks good, keep going.', { origin: { kind: 'human' }, promptSource: 'typed', promptId: randomUUID() }));
|
||||
rows.forEach((r, i) => { r.parentUuid = i ? rows[i - 1]!.uuid : null; });
|
||||
@@ -1644,6 +1645,8 @@ test('#3651: the hook path keeps the first binding when a cwd-reset init is re-r
|
||||
};
|
||||
expect(await run('')).toEqual(OWNED_READ_APPROVAL);
|
||||
expect(await run(footer)).toEqual(OWNED_READ_APPROVAL);
|
||||
expect(await run('', 'unexpected output')).toEqual(OWNED_READ_APPROVAL);
|
||||
expect(await run('', [{ type: 'text', text: 'a' }, { type: 'text', text: 'b' }])).toEqual(OWNED_READ_APPROVAL);
|
||||
});
|
||||
|
||||
for (const [name, content] of [['did not parse', undefined], ['had no single text block', [{ type: 'text', text: 'a' }, { type: 'text', text: 'b' }]]] as const)
|
||||
|
||||
Reference in new issue
Block a user