Files
bowenliang123 87a2893190 refactor(comments): clean up the test-suite comments to the guideline
Apply the AGENTS.md comments guideline to every .ts under tests/: remove
what the code already expresses, keep only what it cannot.

Removed: spec-header coverage inventories the describe/test tree already
names; comments restating the next line's assertion or its message; helper
JSDoc whose body already says it; within-file duplicates; five stale
claims (trendChart's "six aggregated turns" against agg.length === 8,
agentGraph's "six categories" against CATS' seven, fold-timing's "cheapest
call LAST" against a loop that feeds it first, fold-surface's unreachable
plain-JSON note, contextView's "two turns" for a one-turn fixture).

Kept and condensed: the projection-freeze class, strict wire/state-schema
hazards, retention and pricing windows, pairing rules, hostile-input
rationale, fixture and expectation-array ground truth, jsdom mechanics,
and issue-numbered regressions.

Comment lines 2604 -> 2014 (-22%); 85 module headers kept, 30 coverage
inventories dropped; every surviving comment line is within the 140-column
limit, with 36 wrapped lines joined onto fuller ones.

No logic, string, identifier, import or directive changed: a comment-strip
gate proves each file's comment-free code is byte-identical to HEAD, and a
line-level proof pairs all 845 changed lines with an unchanged code part.
pnpm run lint && pnpm run test (106 files / 2061 tests, per-file 100%
coverage) && pnpm run build all pass.
2026-10-10 00:50:55 +08:00

105 lines
4.9 KiB
TypeScript

// The baseline gate's fallback units (src/host/fallback.ts) over the REAL session-projection registry:
// the gate's value arrives through the ordinary snapshot cut, no matter what the log carries.
import assert from 'node:assert/strict'
import { describe, test } from 'vitest'
import { Context } from '@deepseek-ai/cordis'
import SessionStore from '@deepseek-ai/dsh-session'
import type { Session } from '@deepseek-ai/dsh-session'
import SessionProjectionRegistry from '@deepseek-ai/dsh-session-projection'
import { createFallbackActivityDefinition, createFallbackHeadersDefinition, createFallbackTimelineDefinition } from '../../src/host/fallback'
import { BASELINE_DSH_VERSION } from '../../src/shared/version'
const CURRENT = '0.1.1-rc.2'
async function boot() {
const ctx = new Context()
await ctx.plugin(SessionStore)
await ctx.plugin(SessionProjectionRegistry)
ctx.sessionProjections.register(createFallbackTimelineDefinition(CURRENT) as never)
ctx.sessionProjections.register(createFallbackHeadersDefinition() as never)
return ctx
}
function appendAnything(session: Session): void {
session.append('request/header', {
header: { config: { model: 'deepseek-v4-flash', provider: 'deepseek' } },
reason: 'initial',
})
session.append('user/message', {
content: [{ type: 'text', text: 'hi' }],
source: { kind: 'user' },
} as never, { surfaceOp: 'append' })
}
describe('fallback units over the real registry', () => {
test('the gate value arrives through the snapshot cut regardless of the log', async () => {
const ctx = await boot()
const session = ctx.sessions.create()
appendAnything(session)
const timeline = ctx.sessionProjections.snapshot(session).values.contextTimeline
assert.ok(timeline !== undefined)
assert.equal(timeline.ok, true)
assert.deepEqual(timeline.unsupported, { current: CURRENT, minimum: BASELINE_DSH_VERSION })
assert.equal(timeline.current.total, 0, 'nothing is folded')
assert.equal(timeline.requests.length, 0)
assert.equal(timeline.nodes.length, 0)
assert.equal(timeline.archive.length, 0)
assert.equal(timeline.droppedNodes, 0)
assert.equal(timeline.model, undefined)
const headers = ctx.sessionProjections.snapshot(session).values.contextHeaders
assert.ok(headers !== undefined)
assert.deepEqual(headers.headers, [])
})
test('the served views pass the real wire schemas', () => {
const timeline = createFallbackTimelineDefinition(CURRENT)
assert.equal(timeline.wire.viewSchema.safeParse(timeline.wire.view({})).success, true)
const headers = createFallbackHeadersDefinition()
assert.equal(headers.wire.viewSchema.safeParse(headers.wire.view({})).success, true)
})
test('apply is a total identity over any event', () => {
const timeline = createFallbackTimelineDefinition(CURRENT)
const state = timeline.init()
assert.deepEqual(state, {})
assert.ok(timeline.apply(state, { type: 'user/message', seq: 1, time: 0, data: {} } as never) === state)
assert.ok(timeline.apply(state, { type: 'bogus/event' } as never) === state, 'unknown event types pass through')
const headers = createFallbackHeadersDefinition()
assert.ok(headers.apply(state, { type: 'request/header', seq: 1, time: 0, data: null } as never) === state)
})
test('the state schema strips any cached row instead of rejecting it', () => {
const timeline = createFallbackTimelineDefinition(CURRENT)
// A ver-1 row of the REAL headers unit ({headers: [...]}) or any other
// persisted shape seeds the gate's fold stripped to the empty state.
assert.deepEqual(timeline.stateSchema.parse({ headers: [{ seq: 1 }] }), {})
assert.deepEqual(timeline.stateSchema.parse({ surface: [null], sums: {} }), {})
assert.equal(timeline.stateVersion, 1)
})
test('both registry contract generations read their shape off one definition', () => {
const timeline = createFallbackTimelineDefinition(CURRENT)
// Pre-0.1.1 aliases: top-level `schema` + `view`.
assert.equal(timeline.schema.safeParse(timeline.view({})).success, true)
assert.deepEqual(timeline.view({}).unsupported, { current: CURRENT, minimum: BASELINE_DSH_VERSION })
const headers = createFallbackHeadersDefinition()
assert.equal(headers.schema.safeParse(headers.view({})).success, true)
assert.deepEqual(headers.view({}), { headers: [] })
})
test('the activity gate serves an empty ledger through both contract generations', () => {
const activity = createFallbackActivityDefinition()
assert.equal(activity.key, 'contextActivity')
assert.equal(activity.stateVersion, 1)
assert.deepEqual(activity.init(), {})
const state = activity.init()
assert.ok(activity.apply(state, { type: 'assistant/message', seq: 1, time: 0, data: {} } as never) === state)
assert.equal(activity.wire.viewSchema.safeParse(activity.wire.view({})).success, true)
assert.equal(activity.schema.safeParse(activity.view({})).success, true)
assert.deepEqual(activity.view({}), { days: {} })
})
})