397777089e
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
65 lines
2.5 KiB
JavaScript
65 lines
2.5 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import {
|
|
generateParentRandomId,
|
|
buildInheritanceRecord,
|
|
inheritanceFilePath,
|
|
parentSentinelPath,
|
|
subagentBlockPath,
|
|
buildInheritanceEnv,
|
|
} from './subagent-prompt-prefix.mjs';
|
|
|
|
describe('subagent-prompt-prefix / generateParentRandomId', () => {
|
|
it('returns a 64-char hex string (256-bit)', () => {
|
|
const id = generateParentRandomId();
|
|
expect(id).toMatch(/^[a-f0-9]{64}$/);
|
|
});
|
|
it('returns a fresh value each call', () => {
|
|
expect(generateParentRandomId()).not.toBe(generateParentRandomId());
|
|
});
|
|
});
|
|
|
|
describe('subagent-prompt-prefix / buildInheritanceRecord', () => {
|
|
it('builds a schema_version 3 record with constraints', () => {
|
|
const rec = buildInheritanceRecord({
|
|
parentSessionId: 'p1',
|
|
parentRandomId: 'a'.repeat(64),
|
|
nowIso: '2026-05-29T00:00:00.000Z',
|
|
});
|
|
expect(rec.schema_version).toBe(3);
|
|
expect(rec.parent_session_id).toBe('p1');
|
|
expect(rec.parent_random_id).toBe('a'.repeat(64));
|
|
expect(rec.subagent_constraints.can_use_askuser).toBe(false);
|
|
expect(rec.subagent_constraints.can_spawn_task).toBe(false);
|
|
expect(rec.subagent_constraints.max_parallel).toBe(1);
|
|
expect(rec.created_at).toBe('2026-05-29T00:00:00.000Z');
|
|
});
|
|
it('defaults allowed_actions to an array', () => {
|
|
const rec = buildInheritanceRecord({ parentSessionId: 'p', parentRandomId: 'b'.repeat(64) });
|
|
expect(Array.isArray(rec.allowed_actions)).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('subagent-prompt-prefix / path builders', () => {
|
|
it('inheritanceFilePath uses runtime + tool-use-id', () => {
|
|
const p = inheritanceFilePath('tuid-1').replace(/\\/g, '/');
|
|
expect(p).toMatch(/\.claude\/runtime\/subagent-inheritance-tuid-1\.json$/);
|
|
});
|
|
it('parentSentinelPath lives under restricted/', () => {
|
|
const p = parentSentinelPath('rid-9').replace(/\\/g, '/');
|
|
expect(p).toMatch(/\.claude\/runtime\/restricted\/parent-sentinel-rid-9\.json$/);
|
|
});
|
|
it('subagentBlockPath lives under restricted/', () => {
|
|
const p = subagentBlockPath('tuid-2').replace(/\\/g, '/');
|
|
expect(p).toMatch(/\.claude\/runtime\/restricted\/subagent-block-tuid-2\.json$/);
|
|
});
|
|
});
|
|
|
|
describe('subagent-prompt-prefix / buildInheritanceEnv', () => {
|
|
it('returns the three inheritance env vars', () => {
|
|
const env = buildInheritanceEnv({ parentSessionId: 'p1', inheritanceFile: '/x/y.json' });
|
|
expect(env.CLAUDE_PARENT_SESSION_ID).toBe('p1');
|
|
expect(env.CLAUDE_GATE_INHERIT).toBe('true');
|
|
expect(env.CLAUDE_INHERITANCE_FILE).toBe('/x/y.json');
|
|
});
|
|
});
|