@@ -12421,7 +12421,7 @@ Use the attached image as context.
1242112421
1242212422 await session.send('go', undefined, 'turn-1', 'interactive');
1242312423 const scriptPath = (mockSession.shellInitScriptUpdates.at(-1) as Array<{ path: string }>)?.[0]?.path;
12424- assert.ok(scriptPath?.startsWith(TEST_SHELL_INIT_DIR) && scriptPath.endsWith(' init.sh' ), String(scriptPath));
12424+ assert.ok(scriptPath?.startsWith(TEST_SHELL_INIT_DIR) && / init-\d+\ .sh$/.test(scriptPath ), String(scriptPath));
1242512425
1242612426 const afterFirst = mockSession.shellInitScriptUpdates.length;
1242712427 await session.send('go', undefined, 'turn-2', 'interactive');
@@ -12430,12 +12430,14 @@ Use the attached image as context.
1243012430 setConfigValue(SessionConfigKey.ShellInitSnippets, [{ ...initScript, script: 'changed' }]);
1243112431 fireSessionConfigChange({ [SessionConfigKey.ShellInitSnippets]: [{ ...initScript, script: 'changed' }] });
1243212432 await timeout(0);
12433+ const changedScriptPath = (mockSession.shellInitScriptUpdates.at(-1) as Array<{ path: string }>)?.[0]?.path;
12434+ assert.ok(changedScriptPath && changedScriptPath !== scriptPath, String(changedScriptPath));
1243312435
1243412436 setConfigValue(SessionConfigKey.ShellInitSnippets, []);
1243512437 await session.send('go', undefined, 'turn-3', 'interactive');
1243612438 assert.deepStrictEqual(mockSession.shellInitScriptUpdates, [
1243712439 [{ shell: 'bash', path: scriptPath }],
12438- [{ shell: 'bash', path: scriptPath }],
12440+ [{ shell: 'bash', path: changedScriptPath }],
1243912441 [],
1244012442 ]);
1244112443 });
@@ -12455,6 +12457,32 @@ Use the attached image as context.
1245512457 assert.deepStrictEqual(mockSession.shellInitScriptUpdates, [registered]);
1245612458 });
1245712459
12460+ test('keeps the registered script file unchanged when a replacement is rejected', async () => {
12461+ const { session, mockSession, storedFileContents, setConfigValue } = await createAgentSession(disposables);
12462+ setConfigValue(SessionConfigKey.ShellInitSnippets, [initScript]);
12463+ await session.send('go', undefined, 'turn-1', 'interactive');
12464+ const registeredPath = (mockSession.shellInitScriptUpdates.at(-1) as Array<{ path: string }>)[0].path;
12465+
12466+ mockSession.shellInitScriptUpdateSuccess = false;
12467+ setConfigValue(SessionConfigKey.ShellInitSnippets, [{ ...initScript, script: 'rejected' }]);
12468+ await session.send('go', undefined, 'turn-2', 'interactive');
12469+ const updatesAfterRejection = mockSession.shellInitScriptUpdates.length;
12470+
12471+ mockSession.shellInitScriptUpdateSuccess = true;
12472+ setConfigValue(SessionConfigKey.ShellInitSnippets, [initScript]);
12473+ await session.send('go', undefined, 'turn-3', 'interactive');
12474+
12475+ assert.deepStrictEqual({
12476+ registeredContent: storedFileContents.get(URI.file(registeredPath).toString()),
12477+ registeredFileCount: [...storedFileContents.keys()].filter(key => key.includes('/agentHost/shellInit/')).length,
12478+ updateCount: mockSession.shellInitScriptUpdates.length,
12479+ }, {
12480+ registeredContent: initScript.script,
12481+ registeredFileCount: 1,
12482+ updateCount: updatesAfterRejection,
12483+ });
12484+ });
12485+
1245812486 test('each instance owns a distinct directory so a stale cleanup cannot delete a successor script', async () => {
1245912487 // dispose() queues the deletion without awaiting it; a resumed
1246012488 // replacement for the same SDK session may register its script first.
@@ -12489,7 +12517,7 @@ Use the attached image as context.
1248912517 });
1249012518 setConfigValue(SessionConfigKey.ShellInitSnippets, [initScript]);
1249112519 await session.send('go', undefined, 'turn-1', 'interactive');
12492- assert.strictEqual([...storedFileContents.keys()].filter(key => key.includes('/test-session-1/') && key.endsWith('init .sh')).length, 2);
12520+ assert.strictEqual([...storedFileContents.keys()].filter(key => key.includes('/test-session-1/') && key.endsWith('.sh')).length, 2);
1249312521
1249412522 // The session-directory prune must not take the successor's script
1249512523 // with it; only this instance's directory may be removed.
0 commit comments