test(workspace-context): pin empty rendered changes

This commit is contained in:
ZiyaZhang
2026-07-30 03:57:57 -07:00
parent 97005a5223
commit 0fa0405deb
2 changed files with 23 additions and 3 deletions

View File

@@ -30,9 +30,11 @@ export interface RenderedWorkspaceContext {
interface RenderedInstructionContext extends RenderedWorkspaceContext {
/**
* Original files whose file-specific section text survived rendering. This
* is not the complement of `omitted`: a truncated file may be represented
* here and in `truncated`, while a notice-only file appears in neither.
* Original files semantically represented by rendered section text. This is
* not the complement of `omitted`: a truncated file may be represented here
* and in `truncated`, while a notice-only file appears in neither. A genuinely
* empty file counts when its heading survives because that heading conveys
* that the instruction exists and has no content.
*/
represented: LoadedInstructionFile[]
}

View File

@@ -827,6 +827,24 @@ describe('workspace context rendering', () => {
expect(rendered.included).toEqual([file])
})
it('represents a genuinely empty instruction through the framed compact-intro path', () => {
const file = {
absolutePath: '/repo/pkg/AGENTS.md',
displayPath: 'pkg/AGENTS.md',
content: '',
}
const rendered = renderWorkspaceInstructionSet([file], { maxBytes: 300 })
expect(rendered.rendered.text).toContain('<system-reminder>')
expect(rendered.rendered.text).toContain('Workspace instructions were omitted or truncated')
expect(rendered.rendered.text).toContain('Instructions from: pkg/AGENTS.md')
expect(rendered.rendered.truncated).toEqual([
{ displayPath: 'pkg/AGENTS.md', originalBytes: 0, includedBytes: 0 },
])
expect(rendered.included).toEqual([file])
})
it('truncates the compact notice itself when the render budget is smaller than the notice', () => {
const rendered = renderWorkspaceContext([
{ absolutePath: '/repo/pkg/AGENTS.md', displayPath: 'pkg/AGENTS.md', content: 'x'.repeat(1000) },