|
1 | 1 | import assert from 'node:assert/strict'; |
2 | 2 | import { test } from 'vitest'; |
3 | 3 | import { AppError } from '@agent-device/kernel/errors'; |
4 | | -import { buildOpenResult, resolveRequestedOpenSurface } from '../session-open-surface.ts'; |
| 4 | +import { |
| 5 | + buildNextOpenSession, |
| 6 | + buildOpenResult, |
| 7 | + resolveRequestedOpenSurface, |
| 8 | +} from '../session-open-surface.ts'; |
| 9 | +import { |
| 10 | + authoringPublication, |
| 11 | + makeIosSession, |
| 12 | +} from '../../../__tests__/test-utils/session-factories.ts'; |
| 13 | +import { IOS_SIMULATOR } from '../../../__tests__/test-utils/device-fixtures.ts'; |
5 | 14 |
|
6 | 15 | test('resolveRequestedOpenSurface rejects surface flag on iOS', () => { |
7 | 16 | assert.throws( |
@@ -48,3 +57,54 @@ test('buildOpenResult exposes the Vega serial without leaking an internal platfo |
48 | 57 | assert.equal(result.serial, 'amazon-vvd'); |
49 | 58 | assert.equal(result.target, 'tv'); |
50 | 59 | }); |
| 60 | + |
| 61 | +// --- #1533: `--save-script` arms recording through the publication lifecycle, not around it --- |
| 62 | +// |
| 63 | +// A re-open is the surface that used to set `recordSession` on its own. An ABORTED authoring |
| 64 | +// lifecycle is terminal, so the flag must arm nothing here either — otherwise the session keeps |
| 65 | +// paying recording-time costs (the direct-selector fast paths stay disabled) for a recording that |
| 66 | +// can never publish, and the writer is the only thing standing between it and a stray script. |
| 67 | + |
| 68 | +function reopen(existingSession: ReturnType<typeof makeIosSession>, saveScript: boolean) { |
| 69 | + return buildNextOpenSession({ |
| 70 | + existingSession, |
| 71 | + sessionName: existingSession.name, |
| 72 | + device: IOS_SIMULATOR, |
| 73 | + surface: 'app', |
| 74 | + appBundleId: 'com.example.other', |
| 75 | + saveScript, |
| 76 | + }); |
| 77 | +} |
| 78 | + |
| 79 | +test('#1533: re-opening an aborted authoring session with --save-script does not re-arm recording', () => { |
| 80 | + const aborted = makeIosSession('s', { |
| 81 | + recordSession: false, |
| 82 | + scriptPublication: authoringPublication('aborted'), |
| 83 | + }); |
| 84 | + |
| 85 | + assert.equal(reopen(aborted, true).recordSession, false); |
| 86 | +}); |
| 87 | + |
| 88 | +test('#1533: an aborted lifecycle that is already recording is corrected, not carried forward', () => { |
| 89 | + const drifted = makeIosSession('s', { |
| 90 | + recordSession: true, |
| 91 | + scriptPublication: authoringPublication('aborted'), |
| 92 | + }); |
| 93 | + |
| 94 | + assert.equal(reopen(drifted, true).recordSession, false); |
| 95 | +}); |
| 96 | + |
| 97 | +test('a re-open with --save-script still arms recording for a session with no publication yet', () => { |
| 98 | + const plain = makeIosSession('s', { recordSession: false }); |
| 99 | + |
| 100 | + assert.equal(reopen(plain, true).recordSession, true); |
| 101 | +}); |
| 102 | + |
| 103 | +test('a re-open without --save-script leaves an armed authoring session recording', () => { |
| 104 | + const armed = makeIosSession('s', { |
| 105 | + recordSession: true, |
| 106 | + scriptPublication: authoringPublication('armed'), |
| 107 | + }); |
| 108 | + |
| 109 | + assert.equal(reopen(armed, false).recordSession, true); |
| 110 | +}); |
0 commit comments