/** * @fileoverview The agent-case marker: the label that tells a scratch worker workspace * apart from the user's real projects. * * The rules under test are the ones that keep a cleanup affordance safe: reading is * total (anything that is not a well-formed version-1 marker reads as "not * agent-created", never as a half-trusted entry), the origin token is allowlisted * rather than escaped at each use, and writing never throws — a failed marker must not * fail the worker spawn it decorates. * * Port: N/A (pure + a temp dir). */ import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { mkdtemp, rm, readFile, writeFile } from 'node:fs/promises'; import { join } from 'node:path'; import { tmpdir } from 'node:os'; import { AGENT_CASE_MARKER_FILE, AGENT_ORIGIN_CODEMAN_SKILL, AGENT_ORIGIN_SPAWNED_BY_SESSION, buildAgentCaseMarker, normalizeAgentOrigin, parseAgentCaseMarker, readAgentCaseMarker, writeAgentCaseMarker, } from '../src/agent-case-marker.js'; describe('normalizeAgentOrigin', () => { it('accepts a short lowercase token', () => { expect(normalizeAgentOrigin('codeman-skill')).toBe('codeman-skill'); expect(normalizeAgentOrigin(' Codeman-Skill ')).toBe('codeman-skill'); expect(normalizeAgentOrigin('agent.v2_1')).toBe('agent.v2_1'); }); it('drops anything that is not one', () => { // The value reaches a JSON file and the case-manage UI, so it is allowlisted at // the boundary instead of escaped at every use site. expect(normalizeAgentOrigin('