From 2b99d8f5c27119004c3a29d445d71e1cdf11ea79 Mon Sep 17 00:00:00 2001 From: Yichen Jiang Date: Mon, 29 Jun 2026 10:58:43 +0800 Subject: [PATCH] test: cover project instruction configuration branches --- .../core/agent-core/tests/agent-core.spec.ts | 10 ++++ .../core/project-instructions/src/index.ts | 1 + .../tests/project-instructions.spec.ts | 50 +++++++++++++++++++ packages/ui/acp-agent/tests/acp-agent.spec.ts | 12 +++++ .../ui/stdio-agent/tests/stdio-agent.spec.ts | 11 ++++ 5 files changed, 84 insertions(+) diff --git a/packages/core/agent-core/tests/agent-core.spec.ts b/packages/core/agent-core/tests/agent-core.spec.ts index 3f2dc23182..faff57a863 100644 --- a/packages/core/agent-core/tests/agent-core.spec.ts +++ b/packages/core/agent-core/tests/agent-core.spec.ts @@ -128,6 +128,16 @@ describe('dsh-agent-core bundle', () => { } }) + it('supports direct apply with project instructions disabled and no forwarded agents', async () => { + const ctx = new Context() + agentCore.apply(ctx, { projectInstructions: false }) + await new Promise(resolve => setTimeout(resolve, 50)) + + expect(ctx.get('agents')?.list()).toEqual([]) + expect(ctx.get('systemPrompt')).toBeDefined() + await ctx.fiber.dispose() + }) + it('re-exports the loop config schema as its own', () => { expect(agentCore.Config).toBeDefined() expect(agentCore.name).toBe('agent-core') diff --git a/packages/core/project-instructions/src/index.ts b/packages/core/project-instructions/src/index.ts index 58a6e68c65..c518363c45 100644 --- a/packages/core/project-instructions/src/index.ts +++ b/packages/core/project-instructions/src/index.ts @@ -150,6 +150,7 @@ function ancestorChain(root: string, cwd: string): string[] { while (current !== resolvedRoot) { chain.push(current) const parent = dirname(current) + /* v8 ignore next -- defensive guard for direct helper misuse; discovery always passes cwd or an ancestor root. */ if (parent === current) break current = parent } diff --git a/packages/core/project-instructions/tests/project-instructions.spec.ts b/packages/core/project-instructions/tests/project-instructions.spec.ts index 26ded35679..77f46032b9 100644 --- a/packages/core/project-instructions/tests/project-instructions.spec.ts +++ b/packages/core/project-instructions/tests/project-instructions.spec.ts @@ -195,6 +195,24 @@ describe('project instruction discovery', () => { } }) + it('labels the default DSH home as ~/.dsh when HOME points at the configured default', async () => { + const root = await tempRepo() + const home = await tempRepo() + const previousHome = process.env.HOME + try { + process.env.HOME = home + await write(join(home, '.dsh/AGENTS.md'), 'global default rule') + + const files = await discoverBaselineInstructionFiles({ cwd: root }) + + expect(files.map(file => file.displayPath)).toEqual(['~/.dsh/AGENTS.md']) + } finally { + process.env.HOME = previousHome + await rm(root, { recursive: true, force: true }) + await rm(home, { recursive: true, force: true }) + } + }) + it('ignores instruction candidates that are directories', async () => { const root = await tempRepo() const home = await tempRepo() @@ -280,6 +298,38 @@ describe('project instruction rendering', () => { expect(rendered.truncated[0]!.includedBytes).toBeGreaterThan(0) expect(Buffer.byteLength(rendered.text, 'utf8')).toBeLessThanOrEqual(700) }) + + it('omits all text when the render budget is disabled', () => { + const rendered = renderProjectInstructions([ + { absolutePath: '/repo/AGENTS.md', displayPath: 'AGENTS.md', content: 'root rules' }, + ], { maxBytes: 0 }) + + expect(rendered).toEqual({ + text: '', + omitted: [{ absolutePath: '/repo/AGENTS.md', displayPath: 'AGENTS.md', content: 'root rules' }], + truncated: [], + }) + }) + + it('falls back to a compact truncation notice when even the empty heading cannot fit', () => { + const rendered = renderProjectInstructions([ + { absolutePath: '/repo/pkg/AGENTS.md', displayPath: 'pkg/AGENTS.md', content: 'x'.repeat(1000) }, + ], { maxBytes: 100 }) + + expect(rendered.text).toBe('') + expect(rendered.truncated).toEqual([{ displayPath: 'pkg/AGENTS.md', originalBytes: 1000, includedBytes: 0 }]) + expect(Buffer.byteLength(rendered.text, 'utf8')).toBeLessThanOrEqual(100) + }) + + it('truncates the compact notice itself when the render budget is smaller than the notice', () => { + const rendered = renderProjectInstructions([ + { absolutePath: '/repo/pkg/AGENTS.md', displayPath: 'pkg/AGENTS.md', content: 'x'.repeat(1000) }, + ], { maxBytes: 20 }) + + expect(rendered.text).toBe('