test(session): cover the header baseline validation and persistence round-trip
CI per-file coverage flagged the new sandboxMode/approvalPolicy branches: invalid-type cases in both session header validation tables, and a shared persistence-contract case pinning that both backends round-trip the baselines verbatim and keep absent fields ABSENT (presence is the signal the policy owners branch on).
This commit is contained in:
@@ -764,6 +764,8 @@ describe('Session', () => {
|
|||||||
{ header: { ...base, seedLength: '1' }, error: /seedLength must be a non-negative safe integer/ },
|
{ header: { ...base, seedLength: '1' }, error: /seedLength must be a non-negative safe integer/ },
|
||||||
{ header: { ...base, seedLength: 0.5 }, error: /seedLength must be a non-negative safe integer/ },
|
{ header: { ...base, seedLength: 0.5 }, error: /seedLength must be a non-negative safe integer/ },
|
||||||
{ header: { ...base, seedLength: -1 }, error: /seedLength must be a non-negative safe integer/ },
|
{ header: { ...base, seedLength: -1 }, error: /seedLength must be a non-negative safe integer/ },
|
||||||
|
{ header: { ...base, sandboxMode: 1 }, error: /header sandboxMode must be a string/ },
|
||||||
|
{ header: { ...base, approvalPolicy: 1 }, error: /header approvalPolicy must be a string/ },
|
||||||
]
|
]
|
||||||
|
|
||||||
for (const { header, error } of cases) {
|
for (const { header, error } of cases) {
|
||||||
@@ -1011,6 +1013,8 @@ describe('SessionStore', () => {
|
|||||||
{ meta: { delegationDepth: '1' }, error: /delegationDepth must be a non-negative safe integer/ },
|
{ meta: { delegationDepth: '1' }, error: /delegationDepth must be a non-negative safe integer/ },
|
||||||
{ meta: { delegationDepth: 0.5 }, error: /delegationDepth must be a non-negative safe integer/ },
|
{ meta: { delegationDepth: 0.5 }, error: /delegationDepth must be a non-negative safe integer/ },
|
||||||
{ meta: { delegationDepth: -1 }, error: /delegationDepth must be a non-negative safe integer/ },
|
{ meta: { delegationDepth: -1 }, error: /delegationDepth must be a non-negative safe integer/ },
|
||||||
|
{ meta: { sandboxMode: 1 }, error: /header sandboxMode must be a string/ },
|
||||||
|
{ meta: { approvalPolicy: 1 }, error: /header approvalPolicy must be a string/ },
|
||||||
]
|
]
|
||||||
|
|
||||||
for (const [index, { meta, error }] of cases.entries()) {
|
for (const [index, { meta, error }] of cases.entries()) {
|
||||||
|
|||||||
@@ -84,6 +84,36 @@ export function runPersistenceContract(name: string, make: () => Promise<Contrac
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('round-trips the inherited policy baselines exactly and omits them when absent', async () => {
|
||||||
|
const { persistence, dispose } = await make()
|
||||||
|
try {
|
||||||
|
// A delegated child header: the sandbox/approval baselines must
|
||||||
|
// survive storage verbatim — a resumed child falling back to the
|
||||||
|
// deployment default would reopen the delegation bypass.
|
||||||
|
const child: SessionHeader = {
|
||||||
|
...meta('s-baseline', '/work'),
|
||||||
|
delegationDepth: 1,
|
||||||
|
sandboxMode: 'read-only',
|
||||||
|
approvalPolicy: 'never',
|
||||||
|
}
|
||||||
|
await persistence.create(child)
|
||||||
|
await persistence.append(child.id, oneTurnLog())
|
||||||
|
const loaded = await persistence.load(child.id)
|
||||||
|
expect(loaded.meta).toMatchObject({ sandboxMode: 'read-only', approvalPolicy: 'never' })
|
||||||
|
|
||||||
|
// A top-level header: absent baselines stay ABSENT (not null/empty) —
|
||||||
|
// presence is the signal the policy owners branch on.
|
||||||
|
const top = meta('s-no-baseline', '/work')
|
||||||
|
await persistence.create(top)
|
||||||
|
await persistence.append(top.id, oneTurnLog())
|
||||||
|
const reloaded = await persistence.load(top.id)
|
||||||
|
expect('sandboxMode' in reloaded.meta).toBe(false)
|
||||||
|
expect('approvalPolicy' in reloaded.meta).toBe(false)
|
||||||
|
} finally {
|
||||||
|
await dispose()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
it('rejects a fractional creation timestamp without reserving its session id', async () => {
|
it('rejects a fractional creation timestamp without reserving its session id', async () => {
|
||||||
const { persistence, dispose } = await make()
|
const { persistence, dispose } = await make()
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user