@anureo/refactor 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/anureo-refactor.ts +5 -0
- package/package.json +21 -23
- package/src/agent-work.ts +132 -0
- package/src/checks.ts +70 -0
- package/src/cli.ts +214 -0
- package/src/client.ts +91 -0
- package/src/errors.ts +33 -0
- package/src/git-path.ts +47 -0
- package/src/git-tree.ts +55 -0
- package/src/git.ts +42 -0
- package/src/graph-artifacts.ts +70 -0
- package/src/graph.ts +88 -0
- package/src/index.ts +12 -0
- package/src/options.ts +65 -0
- package/src/plan-validation.ts +39 -0
- package/src/{process.d.ts → process.ts} +4 -2
- package/src/{prompts.js → prompts.ts} +162 -62
- package/src/refactor.ts +186 -0
- package/src/{report-store.js → report-store.ts} +9 -7
- package/src/report.ts +44 -0
- package/src/results.ts +81 -0
- package/src/run-lifecycle.ts +117 -0
- package/src/{schema.d.ts → schema.ts} +28 -22
- package/src/source-inventory.ts +17 -0
- package/src/{source-policy.js → source-policy.ts} +31 -37
- package/src/worktree.ts +287 -0
- package/tests/agent-contract.test.ts +188 -0
- package/tests/cli.test.ts +313 -0
- package/tests/fixtures/acp.mjs +38 -0
- package/tests/fixtures/ahp.mjs +50 -0
- package/tests/fixtures/answer.mjs +15 -0
- package/tests/fixtures/codex.mjs +44 -0
- package/tests/fixtures/repograph.ts +17 -0
- package/tests/graph.integration.test.ts +37 -0
- package/tests/helpers.ts +105 -0
- package/tests/refactor.test.ts +437 -0
- package/tests/run-lifecycle.test.ts +82 -0
- package/tests/tree.test.ts +99 -0
- package/tsconfig.json +12 -0
- package/LICENSE +0 -201
- package/bin/anureo-refactor.d.ts +0 -2
- package/bin/anureo-refactor.js +0 -4
- package/src/agent-work.d.ts +0 -41
- package/src/agent-work.js +0 -131
- package/src/checks.d.ts +0 -26
- package/src/checks.js +0 -66
- package/src/cli.d.ts +0 -27
- package/src/cli.js +0 -189
- package/src/client.d.ts +0 -26
- package/src/client.js +0 -73
- package/src/errors.d.ts +0 -9
- package/src/errors.js +0 -22
- package/src/git-path.d.ts +0 -15
- package/src/git-path.js +0 -46
- package/src/git-tree.d.ts +0 -18
- package/src/git-tree.js +0 -56
- package/src/git.d.ts +0 -23
- package/src/git.js +0 -40
- package/src/graph-artifacts.d.ts +0 -19
- package/src/graph-artifacts.js +0 -58
- package/src/graph.d.ts +0 -47
- package/src/graph.js +0 -71
- package/src/index.d.ts +0 -11
- package/src/index.js +0 -4
- package/src/options.d.ts +0 -55
- package/src/options.js +0 -15
- package/src/plan-validation.d.ts +0 -10
- package/src/plan-validation.js +0 -38
- package/src/process.js +0 -10
- package/src/prompts.d.ts +0 -47
- package/src/refactor.d.ts +0 -17
- package/src/refactor.js +0 -168
- package/src/report-store.d.ts +0 -9
- package/src/report.d.ts +0 -6
- package/src/report.js +0 -52
- package/src/results.d.ts +0 -80
- package/src/results.js +0 -0
- package/src/run-lifecycle.d.ts +0 -18
- package/src/run-lifecycle.js +0 -100
- package/src/schema.js +0 -31
- package/src/source-inventory.d.ts +0 -9
- package/src/source-inventory.js +0 -17
- package/src/source-policy.d.ts +0 -11
- package/src/worktree.d.ts +0 -57
- package/src/worktree.js +0 -195
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
// Exercises public sequencing, checkpoints and failure gates through refactorCode.
|
|
2
|
+
import { expect, test } from 'bun:test'
|
|
3
|
+
import { mkdir, readFile, readdir, rename, stat, symlink, writeFile } from 'node:fs/promises'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { createClient, HarnessSdkError, type StructuredOutputToolDefinition } from '@anureo/sdk'
|
|
6
|
+
import { createPiAdapter } from '@anureo/adapter-pi'
|
|
7
|
+
import { fakeFactory } from '../../../packages/adapter/pi/tests/fake-host'
|
|
8
|
+
import { startFake } from '../../../packages/adapter/hermes/tests/helpers'
|
|
9
|
+
import { refactorCode, formatReport } from '../src'
|
|
10
|
+
import { captureTree, treeVersion } from '../src/git-tree'
|
|
11
|
+
import { git } from '../src/git'
|
|
12
|
+
import { edited, fixture, graph, kind, moduleOf, plan, temporary, unchanged } from './helpers'
|
|
13
|
+
|
|
14
|
+
const DESIGN = 'DESIGN MODULE BOUNDARIES'
|
|
15
|
+
const MODULE = 'REFACTOR MODULE'
|
|
16
|
+
|
|
17
|
+
test('refactor completes through the Hermes gateway with schema-validated text', async () => {
|
|
18
|
+
const { cwd } = await fixture()
|
|
19
|
+
const server = await startFake('refactor', { FAKE_HERMES_RESPONSE_MODULE: new URL('./fixtures/answer.mjs', import.meta.url).href })
|
|
20
|
+
try {
|
|
21
|
+
const client = await createClient({ adapter: server.adapter(), identity: { adapterId: 'hermes', runtimeConfigId: 'refactor-test' } })
|
|
22
|
+
try {
|
|
23
|
+
const report = await refactorCode({ client, cwd, reviewOnly: true, noGraph: true })
|
|
24
|
+
expect(report.status).toBe('completed')
|
|
25
|
+
expect(report.plan?.modules[0]?.files).toEqual(['a.ts', 'b.ts'])
|
|
26
|
+
expect((await server.state()).inputs).toHaveLength(3)
|
|
27
|
+
} finally { await client.dispose() }
|
|
28
|
+
} finally { await server.dispose() }
|
|
29
|
+
}, 20_000)
|
|
30
|
+
|
|
31
|
+
test('refactor completes through Pi with its structured output tool', async () => {
|
|
32
|
+
const { cwd } = await fixture()
|
|
33
|
+
const fake = fakeFactory(host => {
|
|
34
|
+
let tool: StructuredOutputToolDefinition | undefined
|
|
35
|
+
Object.assign(host, { async setOutputTool(next?: StructuredOutputToolDefinition) { tool = next } })
|
|
36
|
+
host.script = async (host, prompt) => {
|
|
37
|
+
const value = prompt.startsWith('PLAN') ? plan : unchanged
|
|
38
|
+
expect(await tool?.execute(value)).toMatchObject({ accepted: true })
|
|
39
|
+
await host.assistant('Submitted the result')
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
const client = await createClient({
|
|
43
|
+
adapter: createPiAdapter({ version: '1.5.2', createHost: fake.factory }),
|
|
44
|
+
identity: { adapterId: 'pi', runtimeConfigId: 'refactor-test' },
|
|
45
|
+
})
|
|
46
|
+
try {
|
|
47
|
+
const report = await refactorCode({ client, cwd, noGraph: true, readPermissionMode: 'read-only', editPermissionMode: 'agent-full-access' })
|
|
48
|
+
expect(report.status).toBe('completed')
|
|
49
|
+
expect(report.plan).toEqual(plan)
|
|
50
|
+
} finally { await client.dispose() }
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
/** Require argument failure before filesystem preflight can mask it; fixture cleanup owns the client. */
|
|
54
|
+
test('blank library checks fail before repository setup or agent dispatch', async () => {
|
|
55
|
+
const context = await fixture()
|
|
56
|
+
await expect(refactorCode({ ...context, cwd: join(context.cwd, 'missing'), checks: [' '] })).rejects.toThrow('check commands must be nonempty')
|
|
57
|
+
expect(context.prompts).toHaveLength(0)
|
|
58
|
+
expect(await stat(join(context.cwd, '.anureo')).catch(() => null)).toBeNull()
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('each agent has a worktree and module sessions overlap on the same post-design baseline', async () => {
|
|
62
|
+
let exports = 0
|
|
63
|
+
const order: string[] = []
|
|
64
|
+
const worktrees: string[] = []
|
|
65
|
+
const modulesReady = Promise.withResolvers<void>()
|
|
66
|
+
let runningModules = 0
|
|
67
|
+
const context = await fixture(async (prompt, cwd) => {
|
|
68
|
+
worktrees.push(cwd)
|
|
69
|
+
expect((await git(cwd, 'rev-parse', '--show-toplevel')).trim()).toBe(cwd)
|
|
70
|
+
const module = moduleOf(prompt)
|
|
71
|
+
order.push(module ? `module:${module}` : kind(prompt))
|
|
72
|
+
if (prompt.startsWith(DESIGN)) {
|
|
73
|
+
expect(await readFile(join(cwd, 'README.md'), 'utf8')).toBe('untracked input')
|
|
74
|
+
expect(await readFile(join(cwd, 'a.ts'), 'utf8')).toContain('unstaged')
|
|
75
|
+
await writeFile(join(cwd, 'a.ts'), 'export const value = 1 // design\n')
|
|
76
|
+
return edited()
|
|
77
|
+
}
|
|
78
|
+
expect(await readFile(join(cwd, 'a.ts'), 'utf8')).toContain('// design')
|
|
79
|
+
if (prompt.startsWith('PLAN')) return plan
|
|
80
|
+
|
|
81
|
+
if (++runningModules === 2) modulesReady.resolve()
|
|
82
|
+
await modulesReady.promise
|
|
83
|
+
await writeFile(join(cwd, `${module}.ts`), 'export const value = 2\n')
|
|
84
|
+
expect(await readFile(join(context.cwd, 'a.ts'), 'utf8')).toContain('// design')
|
|
85
|
+
const other = module === 'a' ? 'b' : 'a'
|
|
86
|
+
expect(await readFile(join(cwd, `${other}.ts`), 'utf8')).toContain('value = 1')
|
|
87
|
+
return edited()
|
|
88
|
+
})
|
|
89
|
+
await writeFile(join(context.cwd, 'README.md'), 'untracked input')
|
|
90
|
+
await writeFile(join(context.cwd, 'a.ts'), 'export const value = 1 // unstaged\n')
|
|
91
|
+
const indexBefore = await git(context.cwd, 'ls-files', '--stage')
|
|
92
|
+
const report = await refactorCode({
|
|
93
|
+
...context, checks: ['git diff --exit-code -- .gitignore'],
|
|
94
|
+
readPermissionMode: 'read-only', editPermissionMode: 'agent-full-access',
|
|
95
|
+
graphLoader: async () => { exports++; return graph(context.cwd) },
|
|
96
|
+
})
|
|
97
|
+
expect(report.status).toBe('completed')
|
|
98
|
+
expect(order.slice(0, 2)).toEqual([DESIGN, 'PLAN REFACTOR MODULES'])
|
|
99
|
+
expect(order.slice(2).sort()).toEqual(['module:a', 'module:b'])
|
|
100
|
+
expect(new Set(worktrees).size).toBe(4)
|
|
101
|
+
expect(worktrees).not.toContain(context.cwd)
|
|
102
|
+
expect(exports).toBe(2)
|
|
103
|
+
expect(report.design).toMatchObject({ status: 'applied', changedFiles: ['a.ts'] })
|
|
104
|
+
expect(report.modules.map(item => [item.module.id, item.step?.status])).toEqual([['a', 'applied'], ['b', 'applied']])
|
|
105
|
+
expect(report.modules.every(item => item.step?.checks[0]?.status === 'passed')).toBe(true)
|
|
106
|
+
for (const file of ['a.ts', 'b.ts']) expect(await readFile(join(context.cwd, file), 'utf8')).toContain('value = 2')
|
|
107
|
+
for (const cwd of worktrees) expect(await stat(cwd).catch(() => null)).toBeNull()
|
|
108
|
+
expect((await git(context.cwd, 'worktree', 'list', '--porcelain')).match(/^worktree /gm)).toHaveLength(1)
|
|
109
|
+
expect(await git(context.cwd, 'ls-files', '--stage')).toBe(indexBefore)
|
|
110
|
+
expect(context.adapter.opened.filter(session => session.permissionMode === 'read-only')).toHaveLength(1)
|
|
111
|
+
expect(context.adapter.opened.filter(session => session.permissionMode === 'agent-full-access')).toHaveLength(3)
|
|
112
|
+
expect(context.prompts.find(prompt => prompt.startsWith(MODULE))).toContain('Cross-module design step already done in this run: Edited')
|
|
113
|
+
expect(JSON.parse(await readFile(join(report.directory, 'report.json'), 'utf8'))).toEqual(report)
|
|
114
|
+
expect(await stat(join(context.cwd, '.anureo/refactor/writer.lock')).catch(() => null)).toBeNull()
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
/** Inspect scripted prompts without edits so review instructions and report wording stay aligned. */
|
|
118
|
+
test('prompts name the problem catalog, the graph guide and the mode', async () => {
|
|
119
|
+
const context = await fixture()
|
|
120
|
+
const report = await refactorCode({ ...context, reviewOnly: true })
|
|
121
|
+
expect(report.status).toBe('completed')
|
|
122
|
+
const design = context.prompts.find(prompt => prompt.startsWith(DESIGN))!
|
|
123
|
+
const module = context.prompts.find(prompt => prompt.startsWith(MODULE))!
|
|
124
|
+
for (const prompt of [design, module]) {
|
|
125
|
+
expect(prompt).toContain('MODE: READ ONLY')
|
|
126
|
+
expect(prompt).toContain('Graph artifact:')
|
|
127
|
+
expect(prompt).toContain('local_name')
|
|
128
|
+
expect(prompt).toContain('Optimize for the cost of understanding and changing the code.')
|
|
129
|
+
expect(prompt.replace(/\s+/g, ' ')).toContain('verify call targets, imports, aliases, re-exports and callback registration/invocation in source')
|
|
130
|
+
expect(prompt).toContain('Missing edges do not prove absence of calls')
|
|
131
|
+
}
|
|
132
|
+
expect(design).toContain('Wrong dependency direction')
|
|
133
|
+
expect(design).toContain('Import cycles between files')
|
|
134
|
+
expect(module).toContain('shares mutable variables across them')
|
|
135
|
+
expect(module).toContain('five or more positional parameters')
|
|
136
|
+
for (const prompt of [design, module]) {
|
|
137
|
+
expect(prompt).toContain('Comment WHY, not WHAT')
|
|
138
|
+
expect(prompt).toContain('doc comment stating')
|
|
139
|
+
expect(prompt).toContain('Documentation conventions and tags:')
|
|
140
|
+
expect(prompt).toContain('re-export chains')
|
|
141
|
+
expect(prompt).toContain('Declaration order:')
|
|
142
|
+
}
|
|
143
|
+
expect(design).toContain('Design documentation scope:')
|
|
144
|
+
expect(module).toContain('Module documentation scope:')
|
|
145
|
+
expect(module).toContain('including declarations\nwhose implementation stays unchanged')
|
|
146
|
+
expect(formatReport(report)).toContain('review only')
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
/** Verify explicit edit checks reach the agent even when its response leaves the tree unchanged. */
|
|
150
|
+
test('edit mode states how to edit and lists the validation commands', async () => {
|
|
151
|
+
const context = await fixture()
|
|
152
|
+
await refactorCode({ ...context, checks: ['true'] })
|
|
153
|
+
const module = context.prompts.find(prompt => prompt.startsWith(MODULE))!
|
|
154
|
+
expect(module).toContain('MODE: EDIT')
|
|
155
|
+
expect(module).toContain('Validation commands: ["true"]')
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
/** Feed malformed assignments through the real planner boundary; no module may start after rejection. */
|
|
159
|
+
test.each([
|
|
160
|
+
{ ...plan, modules: [plan.modules[0]] },
|
|
161
|
+
{ ...plan, modules: [plan.modules[0], plan.modules[0]] },
|
|
162
|
+
{ ...plan, modules: [plan.modules[0], { ...plan.modules[1], id: 'A' }] },
|
|
163
|
+
{ ...plan, modules: [{ ...plan.modules[0], files: ['a.ts', 'not-in-inventory.ts'] }, plan.modules[1]] },
|
|
164
|
+
])('rejects missing, duplicate and invented inventory assignments before any module agent', async invalid => {
|
|
165
|
+
const context = await fixture(prompt => prompt.startsWith('PLAN') ? invalid : unchanged)
|
|
166
|
+
const report = await refactorCode({ ...context, checks: [] })
|
|
167
|
+
expect(report.status).toBe('incomplete')
|
|
168
|
+
expect(context.prompts.some(prompt => prompt.startsWith(MODULE))).toBe(false)
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
/** Inject an unknown SDK outcome after a real edit; planning stops and the target retains its original contents. */
|
|
172
|
+
test('a failed design step stops before planning and records its observed edit', async () => {
|
|
173
|
+
const context = await fixture(async (_prompt, cwd) => {
|
|
174
|
+
await writeFile(join(cwd, 'a.ts'), 'export const value = 2\n')
|
|
175
|
+
return new HarnessSdkError('RECEIPT_LOST', 'Unknown', false, true)
|
|
176
|
+
})
|
|
177
|
+
const report = await refactorCode({ ...context, checks: [] })
|
|
178
|
+
expect(report.status).toBe('incomplete')
|
|
179
|
+
expect(report.design).toMatchObject({ status: 'failed', changedFiles: ['a.ts'], failure: { code: 'RECEIPT_LOST', outcomeUnknown: true } })
|
|
180
|
+
expect(await readFile(join(context.cwd, 'a.ts'), 'utf8')).toBe('export const value = 1\n')
|
|
181
|
+
expect(context.prompts).toHaveLength(1)
|
|
182
|
+
expect(formatReport(report)).toContain('execution outcome is unknown')
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
test('a failed module leaves the target untouched for its assignment while siblings merge', async () => {
|
|
186
|
+
const context = await fixture(async (prompt, cwd) => {
|
|
187
|
+
if (prompt.startsWith('PLAN')) return plan
|
|
188
|
+
const module = moduleOf(prompt)
|
|
189
|
+
if (!module) return unchanged
|
|
190
|
+
await writeFile(join(cwd, `${module}.ts`), 'export const value = 2\n')
|
|
191
|
+
return module === 'a' ? new HarnessSdkError('NATIVE_FAILED', 'Writer failed') : edited()
|
|
192
|
+
})
|
|
193
|
+
const report = await refactorCode({ ...context, checks: [] })
|
|
194
|
+
expect(report.status).toBe('incomplete')
|
|
195
|
+
expect(report.modules[0]?.step).toMatchObject({ status: 'failed', changedFiles: ['a.ts'] })
|
|
196
|
+
expect(report.modules[1]?.step).toMatchObject({ status: 'applied', changedFiles: ['b.ts'] })
|
|
197
|
+
expect(await readdir(report.directory)).not.toContain('module-a.patch')
|
|
198
|
+
expect(await readFile(join(context.cwd, 'a.ts'), 'utf8')).toContain('value = 1')
|
|
199
|
+
expect(await readFile(join(context.cwd, 'b.ts'), 'utf8')).toContain('value = 2')
|
|
200
|
+
expect((await git(context.cwd, 'worktree', 'list', '--porcelain')).match(/^worktree /gm)).toHaveLength(1)
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
test('verified work merges while an earlier agent is still running, and competing additions fail', async () => {
|
|
204
|
+
const merged = Promise.withResolvers<void>()
|
|
205
|
+
const context = await fixture(async (prompt, cwd) => {
|
|
206
|
+
if (prompt.startsWith('PLAN')) return plan
|
|
207
|
+
const module = moduleOf(prompt)
|
|
208
|
+
if (!module) return unchanged
|
|
209
|
+
if (module === 'a') {
|
|
210
|
+
await merged.promise
|
|
211
|
+
expect(await readFile(join(context.cwd, 'b.ts'), 'utf8')).toContain('value = 2')
|
|
212
|
+
expect(await readFile(join(cwd, 'b.ts'), 'utf8')).toContain('value = 1')
|
|
213
|
+
}
|
|
214
|
+
await writeFile(join(cwd, `${module}.ts`), 'export const value = 2\n')
|
|
215
|
+
await writeFile(join(cwd, 'shared.ts'), `export const owner = '${module}'\n`)
|
|
216
|
+
return edited()
|
|
217
|
+
})
|
|
218
|
+
const report = await refactorCode({
|
|
219
|
+
...context, concurrency: 2,
|
|
220
|
+
checks: [{ executable: process.execPath, args: ['-e', 'if (!(await Bun.file("shared.ts").text()).includes("owner")) process.exit(1)'] }],
|
|
221
|
+
onProgress: event => { if (event === 'module/b: applied') merged.resolve() },
|
|
222
|
+
})
|
|
223
|
+
expect(report.status).toBe('incomplete')
|
|
224
|
+
expect(report.modules[0]?.step).toMatchObject({ status: 'failed', error: 'Source changed during refactor: shared.ts' })
|
|
225
|
+
expect(report.modules[1]?.step).toMatchObject({ status: 'applied', checks: [{ status: 'passed' }] })
|
|
226
|
+
expect(await readFile(join(context.cwd, 'shared.ts'), 'utf8')).toContain("owner = 'b'")
|
|
227
|
+
expect(await readFile(join(context.cwd, 'a.ts'), 'utf8')).toContain('value = 1')
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
test('edits to another module and review-only writes stay out of the target checkout', async () => {
|
|
231
|
+
const context = await fixture(async (prompt, cwd) => {
|
|
232
|
+
if (prompt.startsWith('PLAN')) return plan
|
|
233
|
+
if (moduleOf(prompt) !== 'a') return unchanged
|
|
234
|
+
await writeFile(join(cwd, 'b.ts'), 'export const value = 2\n')
|
|
235
|
+
return edited()
|
|
236
|
+
})
|
|
237
|
+
for (const reviewOnly of [false, true]) {
|
|
238
|
+
const report = await refactorCode({ ...context, reviewOnly, checks: [] })
|
|
239
|
+
expect(report.status).toBe('incomplete')
|
|
240
|
+
expect(report.modules[0]?.step).toMatchObject({
|
|
241
|
+
status: 'failed', changedFiles: ['b.ts'],
|
|
242
|
+
error: reviewOnly ? 'Review-only agent modified files' : 'Module edited paths outside its assignment: b.ts',
|
|
243
|
+
})
|
|
244
|
+
expect(await readFile(join(context.cwd, 'b.ts'), 'utf8')).toContain('value = 1')
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
test('failed validation retains its output and prevents unverified changes from reaching the target', async () => {
|
|
249
|
+
const context = await fixture(async (prompt, cwd) => {
|
|
250
|
+
if (prompt.startsWith('PLAN')) return plan
|
|
251
|
+
const module = moduleOf(prompt)
|
|
252
|
+
if (!module) return unchanged
|
|
253
|
+
await writeFile(join(cwd, `${module}.ts`), 'export const value = 2\n')
|
|
254
|
+
return edited()
|
|
255
|
+
})
|
|
256
|
+
const report = await refactorCode({ ...context, checks: [
|
|
257
|
+
{ executable: process.execPath, args: ['-e', 'if ((await Bun.file("a.ts").text()).includes("value = 2")) { console.error("validation-broken"); process.exit(7) }'] },
|
|
258
|
+
{ executable: process.execPath, args: ['-e', 'if (!(await Bun.file("b.ts").text()).includes("value = 2")) process.exit(8)'] },
|
|
259
|
+
] })
|
|
260
|
+
expect(report.status).toBe('incomplete')
|
|
261
|
+
expect(report.modules[0]?.step).toMatchObject({
|
|
262
|
+
status: 'failed',
|
|
263
|
+
checks: [{ status: 'failed', output: expect.stringContaining('validation-broken') }],
|
|
264
|
+
})
|
|
265
|
+
expect(report.modules[1]?.step).toMatchObject({ status: 'applied', checks: [{ status: 'passed' }, { status: 'passed' }] })
|
|
266
|
+
expect(await readFile(join(context.cwd, 'a.ts'), 'utf8')).toBe('export const value = 1\n')
|
|
267
|
+
expect(await readFile(join(context.cwd, 'b.ts'), 'utf8')).toBe('export const value = 2\n')
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
test('the plan checkpoint is published before either module starts', async () => {
|
|
271
|
+
let directory = ''
|
|
272
|
+
const context = await fixture(async prompt => {
|
|
273
|
+
if (prompt.startsWith(DESIGN)) return unchanged
|
|
274
|
+
const saved = JSON.parse(await readFile(join(directory, 'report.json'), 'utf8'))
|
|
275
|
+
expect(saved.design.status).toBe('unchanged')
|
|
276
|
+
if (prompt.startsWith('PLAN')) {
|
|
277
|
+
expect(saved.plan).toBeNull()
|
|
278
|
+
return plan
|
|
279
|
+
}
|
|
280
|
+
expect(saved.plan).toEqual(plan)
|
|
281
|
+
expect(saved.modules).toEqual([])
|
|
282
|
+
return unchanged
|
|
283
|
+
})
|
|
284
|
+
const report = await refactorCode({ ...context, checks: [],
|
|
285
|
+
onProgress: event => { if (event.startsWith('run: ')) directory = event.slice('run: '.length) },
|
|
286
|
+
})
|
|
287
|
+
expect(report.status).toBe('completed')
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
test('a failed post-design graph refresh prevents module dispatch and releases the lock', async () => {
|
|
291
|
+
const context = await fixture(async (prompt, cwd) => {
|
|
292
|
+
if (prompt.startsWith('PLAN')) return plan
|
|
293
|
+
if (prompt.startsWith(DESIGN)) {
|
|
294
|
+
await writeFile(join(cwd, 'a.ts'), 'export const value = 2\n')
|
|
295
|
+
return edited()
|
|
296
|
+
}
|
|
297
|
+
return unchanged
|
|
298
|
+
})
|
|
299
|
+
let exports = 0
|
|
300
|
+
const report = await refactorCode({ ...context, checks: [],
|
|
301
|
+
graphLoader: async () => {
|
|
302
|
+
if (++exports === 2) throw new Error('Graph refresh unavailable')
|
|
303
|
+
return graph(context.cwd)
|
|
304
|
+
},
|
|
305
|
+
})
|
|
306
|
+
expect(report.status).toBe('incomplete')
|
|
307
|
+
expect(report.errors).toEqual(['Graph refresh unavailable'])
|
|
308
|
+
expect(report.modules).toEqual([])
|
|
309
|
+
expect(context.prompts.some(prompt => prompt.startsWith(MODULE))).toBe(false)
|
|
310
|
+
expect(await readFile(join(context.cwd, 'a.ts'), 'utf8')).toBe('export const value = 2\n')
|
|
311
|
+
expect(JSON.parse(await readFile(join(report.directory, 'report.json'), 'utf8'))).toEqual(report)
|
|
312
|
+
expect(await stat(join(context.cwd, '.anureo/refactor/writer.lock')).catch(() => null)).toBeNull()
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
/** Discover real package scripts and confirm typecheck failure prevents the test script from running. */
|
|
316
|
+
test('default validation discovers root package scripts and stops on a failing typecheck', async () => {
|
|
317
|
+
const context = await fixture(async (prompt, cwd) => {
|
|
318
|
+
if (prompt.startsWith('PLAN')) return plan
|
|
319
|
+
if (moduleOf(prompt) === 'a') await writeFile(join(cwd, 'a.ts'), 'const named = 1; export { named as value }\n')
|
|
320
|
+
return moduleOf(prompt) === 'a' ? edited() : unchanged
|
|
321
|
+
})
|
|
322
|
+
await writeFile(join(context.cwd, 'package.json'), JSON.stringify({ packageManager: 'bun@1.4.2', scripts: { typecheck: 'exit 9', test: 'exit 0' } }))
|
|
323
|
+
const report = await refactorCode(context)
|
|
324
|
+
expect(report.status).toBe('incomplete')
|
|
325
|
+
expect(report.modules[0]?.step?.checks).toMatchObject([{ command: 'bun run typecheck', status: 'failed' }])
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
test('validation resolves installed workspace links to edited files in the agent worktree', async () => {
|
|
329
|
+
const context = await fixture(async (prompt, cwd) => {
|
|
330
|
+
if (prompt.startsWith('PLAN')) return plan
|
|
331
|
+
if (moduleOf(prompt) !== 'a') return unchanged
|
|
332
|
+
await writeFile(join(cwd, 'a.ts'), 'export const value = 2\n')
|
|
333
|
+
return edited()
|
|
334
|
+
})
|
|
335
|
+
await mkdir(join(context.cwd, 'node_modules'))
|
|
336
|
+
await symlink(context.cwd, join(context.cwd, 'node_modules', 'workspace'), 'junction')
|
|
337
|
+
await writeFile(join(context.cwd, '.gitignore'), '.anureo/\nnode_modules/\n')
|
|
338
|
+
const report = await refactorCode({ ...context, checks: [
|
|
339
|
+
{ executable: process.execPath, args: ['-e', 'if ((await import("workspace/a.ts")).value !== 2) process.exit(9)'] },
|
|
340
|
+
] })
|
|
341
|
+
expect(report.modules[0]?.step).toMatchObject({ status: 'applied', checks: [{ status: 'passed' }] })
|
|
342
|
+
expect(await readFile(join(context.cwd, 'a.ts'), 'utf8')).toContain('value = 2')
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
test('a passing command that rewrites agent source prevents the merge', async () => {
|
|
346
|
+
const context = await fixture(async (prompt, cwd) => {
|
|
347
|
+
if (prompt.startsWith('PLAN')) return plan
|
|
348
|
+
if (moduleOf(prompt) !== 'a') return unchanged
|
|
349
|
+
await writeFile(join(cwd, 'a.ts'), 'export const value = 2\n')
|
|
350
|
+
return edited()
|
|
351
|
+
})
|
|
352
|
+
const report = await refactorCode({ ...context, checks: [
|
|
353
|
+
{ executable: process.execPath, args: ['-e', 'await Bun.write("a.ts", "export const value = 3\\n")'] },
|
|
354
|
+
] })
|
|
355
|
+
expect(report.modules[0]?.step).toMatchObject({ status: 'failed', error: 'Validation modified source files: a.ts' })
|
|
356
|
+
expect(await readFile(join(context.cwd, 'a.ts'), 'utf8')).toContain('value = 1')
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
/** Move/add files during design so the host diff and post-design inventory use observed paths. */
|
|
360
|
+
test('moves and new files need no declaration and are reported from the real diff', async () => {
|
|
361
|
+
const context = await fixture(async (prompt, cwd) => {
|
|
362
|
+
if (prompt.startsWith('PLAN')) return { ...plan, modules: [{ ...plan.modules[0], files: ['moved.ts', 'types.ts'] }, plan.modules[1]] }
|
|
363
|
+
if (prompt.startsWith(DESIGN)) {
|
|
364
|
+
await rename(join(cwd, 'a.ts'), join(cwd, 'moved.ts'))
|
|
365
|
+
await writeFile(join(cwd, 'types.ts'), 'export type T = 1\n')
|
|
366
|
+
return edited('Moved a.ts, added types.ts')
|
|
367
|
+
}
|
|
368
|
+
return unchanged
|
|
369
|
+
})
|
|
370
|
+
const report = await refactorCode({ ...context, checks: [] })
|
|
371
|
+
expect(report.status).toBe('completed')
|
|
372
|
+
expect(report.design?.changedFiles).toEqual(['a.ts', 'moved.ts', 'types.ts'])
|
|
373
|
+
expect(report.plan).not.toBeNull()
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
/** Add a design-time source and require its inclusion in the subsequent planning prompt. */
|
|
377
|
+
test('the plan is made from the tree after the design step', async () => {
|
|
378
|
+
const context = await fixture(async (prompt, cwd) => {
|
|
379
|
+
if (prompt.startsWith(DESIGN)) { await writeFile(join(cwd, 'extra.ts'), 'export const extra = 1\n'); return edited() }
|
|
380
|
+
if (prompt.startsWith('PLAN')) return { ...plan, modules: [{ ...plan.modules[0], files: ['a.ts', 'extra.ts'] }, plan.modules[1]] }
|
|
381
|
+
return unchanged
|
|
382
|
+
})
|
|
383
|
+
const report = await refactorCode({ ...context, checks: [] })
|
|
384
|
+
expect(report.status).toBe('completed')
|
|
385
|
+
expect(context.prompts.find(prompt => prompt.startsWith('PLAN'))).toContain('"extra.ts"')
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
/** Use an external fixture path to ensure source safety rejects links before graph or agent work. */
|
|
389
|
+
test.skipIf(process.platform === 'win32')('a symlinked source file is rejected before any agent runs', async () => {
|
|
390
|
+
const outside = await temporary()
|
|
391
|
+
const context = await fixture()
|
|
392
|
+
await writeFile(join(outside, 'x.ts'), 'export const x = 1\n')
|
|
393
|
+
await symlink(join(outside, 'x.ts'), join(context.cwd, 'linked.ts'))
|
|
394
|
+
const report = await refactorCode({ ...context })
|
|
395
|
+
expect(report.status).toBe('incomplete')
|
|
396
|
+
expect(report.errors.join()).toContain('Symlink')
|
|
397
|
+
expect(context.prompts).toHaveLength(0)
|
|
398
|
+
})
|
|
399
|
+
|
|
400
|
+
/** Precreate a competing writer lock; acquisition failure must reject without dispatching agents. */
|
|
401
|
+
test('one cooperating process owns the tree', async () => {
|
|
402
|
+
const context = await fixture()
|
|
403
|
+
await mkdir(join(context.cwd, '.anureo/refactor'), { recursive: true })
|
|
404
|
+
await writeFile(join(context.cwd, '.anureo/refactor/writer.lock'), 'active')
|
|
405
|
+
await expect(refactorCode(context)).rejects.toThrow('Cannot acquire refactor lock')
|
|
406
|
+
expect(context.prompts).toHaveLength(0)
|
|
407
|
+
})
|
|
408
|
+
|
|
409
|
+
/** Throw from the observer and supply a failing check; unchanged steps must still complete without edits. */
|
|
410
|
+
test('progress errors are observational and unchanged steps run no checks', async () => {
|
|
411
|
+
const context = await fixture()
|
|
412
|
+
const before = treeVersion(await captureTree(context.cwd))
|
|
413
|
+
const report = await refactorCode({ ...context, checks: ['exit 1'], onProgress: () => { throw new Error('Sink unavailable') } })
|
|
414
|
+
expect(report.status).toBe('completed')
|
|
415
|
+
expect(report.modules.map(item => item.step?.status)).toEqual(['unchanged', 'unchanged'])
|
|
416
|
+
expect(report.progressErrors.length).toBeGreaterThan(0)
|
|
417
|
+
expect(treeVersion(await captureTree(context.cwd))).toBe(before)
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
/** Target a nested Git directory to verify inventory and graph context do not expand to the repository root. */
|
|
421
|
+
test('a subdirectory of a Git repository is a valid target and only its files are in scope', async () => {
|
|
422
|
+
const context = await fixture(async (prompt, cwd) => {
|
|
423
|
+
expect(await readFile(join(cwd, '..', 'a.ts'), 'utf8')).toContain('value = 1')
|
|
424
|
+
if (prompt.startsWith('PLAN')) return plan
|
|
425
|
+
if (moduleOf(prompt) !== 'a') return unchanged
|
|
426
|
+
await writeFile(join(cwd, 'a.ts'), 'export const value = 3\n')
|
|
427
|
+
return edited()
|
|
428
|
+
})
|
|
429
|
+
await mkdir(join(context.cwd, 'pkg'))
|
|
430
|
+
const cwd = join(context.cwd, 'pkg')
|
|
431
|
+
await Promise.all(['a.ts', 'b.ts'].map(file => writeFile(join(cwd, file), 'export const value = 1\n')))
|
|
432
|
+
const report = await refactorCode({ ...context, cwd, checks: [], graphLoader: async () => graph(cwd) })
|
|
433
|
+
expect(report.status).toBe('completed')
|
|
434
|
+
expect(await readFile(join(cwd, 'a.ts'), 'utf8')).toContain('value = 3')
|
|
435
|
+
expect(await readFile(join(context.cwd, 'a.ts'), 'utf8')).toContain('value = 1')
|
|
436
|
+
expect(JSON.parse(context.prompts.find(prompt => prompt.startsWith('PLAN'))!.split('Inventory: ')[1]!.split('\n')[0]!)).toEqual(['a.ts', 'b.ts'])
|
|
437
|
+
})
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { expect, test } from 'bun:test'
|
|
2
|
+
import { mkdir, readFile, rm, stat } from 'node:fs/promises'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { saveReport } from '../src/report-store'
|
|
5
|
+
import type { RefactorReport } from '../src/results'
|
|
6
|
+
import { withRun } from '../src/run-lifecycle'
|
|
7
|
+
import { fixture } from './helpers'
|
|
8
|
+
|
|
9
|
+
test('lifecycle holds the lock through body execution and records synchronous observer failures in order', async () => {
|
|
10
|
+
const context = await fixture()
|
|
11
|
+
const events: string[] = []
|
|
12
|
+
let competingBodyRan = false
|
|
13
|
+
const report = await withRun({
|
|
14
|
+
...context,
|
|
15
|
+
onProgress: event => {
|
|
16
|
+
events.push(event)
|
|
17
|
+
throw new Error(`Observer ${events.length}`)
|
|
18
|
+
},
|
|
19
|
+
}, async (report, progress) => {
|
|
20
|
+
expect(report.status).toBe('incomplete')
|
|
21
|
+
expect(events).toEqual([`run: ${report.directory}`])
|
|
22
|
+
await expect(withRun(context, async () => { competingBodyRan = true })).rejects.toThrow('Cannot acquire refactor lock')
|
|
23
|
+
expect((await stat(join(context.cwd, '.anureo/refactor/writer.lock'))).isFile()).toBe(true)
|
|
24
|
+
progress('body: finished')
|
|
25
|
+
})
|
|
26
|
+
expect(competingBodyRan).toBe(false)
|
|
27
|
+
expect(events).toEqual([`run: ${report.directory}`, 'body: finished'])
|
|
28
|
+
expect(report.status).toBe('completed')
|
|
29
|
+
expect(report.progressErrors).toEqual(['Observer 1', 'Observer 2'])
|
|
30
|
+
await expectFinalizedRun(report)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('lifecycle publishes classified body failures before releasing the lock', async () => {
|
|
34
|
+
const context = await fixture()
|
|
35
|
+
const report = await withRun(context, async () => {
|
|
36
|
+
throw Object.assign(new Error('Body unavailable'), {
|
|
37
|
+
code: 'RECEIPT_LOST', outcomeUnknown: true, details: { cleanupErrors: ['Release unavailable'] },
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
expect(report.status).toBe('incomplete')
|
|
41
|
+
expect(report.errors).toEqual(['Body unavailable'])
|
|
42
|
+
expect(report.failure).toEqual({ code: 'RECEIPT_LOST', outcomeUnknown: true, cleanupFailed: true })
|
|
43
|
+
await expectFinalizedRun(report)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// Obstruct real paths so failure precedence is exercised without replacing filesystem calls.
|
|
47
|
+
test.each([
|
|
48
|
+
{ publicationFails: true, removalFails: false },
|
|
49
|
+
{ publicationFails: false, removalFails: true },
|
|
50
|
+
{ publicationFails: true, removalFails: true },
|
|
51
|
+
])('finalization handles publication failure $publicationFails and removal failure $removalFails', async ({ publicationFails, removalFails }) => {
|
|
52
|
+
const context = await fixture()
|
|
53
|
+
const lockPath = join(context.cwd, '.anureo/refactor/writer.lock')
|
|
54
|
+
let directory = ''
|
|
55
|
+
let checkpoint = ''
|
|
56
|
+
const run = withRun(context, async report => {
|
|
57
|
+
directory = report.directory
|
|
58
|
+
await saveReport(report)
|
|
59
|
+
checkpoint = await readFile(join(directory, 'report.json'), 'utf8')
|
|
60
|
+
if (publicationFails) await mkdir(join(directory, 'report.json.tmp'))
|
|
61
|
+
if (removalFails) {
|
|
62
|
+
await rm(lockPath)
|
|
63
|
+
await mkdir(lockPath)
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
const error = await run.then(() => null, cause => cause)
|
|
67
|
+
expect(error).toMatchObject({ path: removalFails ? lockPath : join(directory, 'report.json.tmp') })
|
|
68
|
+
const saved = await readFile(join(directory, 'report.json'), 'utf8')
|
|
69
|
+
if (publicationFails) expect(saved).toBe(checkpoint)
|
|
70
|
+
else expect(JSON.parse(saved).status).toBe('completed')
|
|
71
|
+
if (removalFails) expect((await stat(lockPath)).isDirectory()).toBe(true)
|
|
72
|
+
else await expect(stat(lockPath)).rejects.toMatchObject({ code: 'ENOENT' })
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
/** Assert the returned record was fully published and writer ownership was released. */
|
|
76
|
+
async function expectFinalizedRun(report: RefactorReport): Promise<void> {
|
|
77
|
+
const saved = await readFile(join(report.directory, 'report.json'), 'utf8')
|
|
78
|
+
expect(JSON.parse(saved)).toEqual(report)
|
|
79
|
+
expect(saved.endsWith('\n')).toBe(true)
|
|
80
|
+
await expect(stat(join(report.directory, 'report.json.tmp'))).rejects.toMatchObject({ code: 'ENOENT' })
|
|
81
|
+
await expect(stat(join(report.cwd, '.anureo/refactor/writer.lock'))).rejects.toMatchObject({ code: 'ENOENT' })
|
|
82
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Verifies Git snapshots and source eligibility against real filesystem entries.
|
|
2
|
+
import { expect, test } from 'bun:test'
|
|
3
|
+
import { chmod, lstat, mkdir, rm, symlink, writeFile } from 'node:fs/promises'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { captureTree, changes, treeVersion } from '../src/git-tree'
|
|
6
|
+
import { gitFiles } from '../src/git'
|
|
7
|
+
import { exec } from '../src/process'
|
|
8
|
+
import { isSource, isTextSource } from '../src/source-policy'
|
|
9
|
+
import { fixture, temporary } from './helpers'
|
|
10
|
+
|
|
11
|
+
/** Exercise Git visibility separately from snapshot exclusions, including force-added run storage. */
|
|
12
|
+
test('snapshots sort visible files, omit deleted entries and metadata, and retain non-source files', async () => {
|
|
13
|
+
const { cwd } = await fixture()
|
|
14
|
+
await writeFile(join(cwd, '.gitignore'), '.anureo/\nignored.ts\n')
|
|
15
|
+
await writeFile(join(cwd, 'ignored.ts'), 'ignored')
|
|
16
|
+
await writeFile(join(cwd, 'notes.txt'), 'untracked text')
|
|
17
|
+
await mkdir(join(cwd, '.anureo'))
|
|
18
|
+
await writeFile(join(cwd, '.anureo', 'report.ts'), 'run output')
|
|
19
|
+
await exec('git', ['-C', cwd, 'add', '--force', '.anureo/report.ts'])
|
|
20
|
+
await rm(join(cwd, 'b.ts'))
|
|
21
|
+
|
|
22
|
+
expect(await gitFiles(cwd)).toEqual(['.anureo/report.ts', '.gitignore', 'a.ts', 'b.ts', 'notes.txt'])
|
|
23
|
+
const tree = await captureTree(cwd)
|
|
24
|
+
expect([...tree.keys()]).toEqual(['.gitignore', 'a.ts', 'notes.txt'])
|
|
25
|
+
const version = treeVersion(tree)
|
|
26
|
+
await writeFile(join(cwd, '.anureo', 'report.ts'), 'changed run output')
|
|
27
|
+
expect(treeVersion(await captureTree(cwd))).toBe(version)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
/** Compare real file/link edits so content, mode and link text remain independently observable. */
|
|
31
|
+
test.skipIf(process.platform === 'win32')('snapshot changes track content and modes, and hash symlink text without reading its destination', async () => {
|
|
32
|
+
const { cwd } = await fixture()
|
|
33
|
+
const outside = await temporary()
|
|
34
|
+
const destination = join(outside, 'destination.ts')
|
|
35
|
+
await writeFile(destination, 'external content')
|
|
36
|
+
await symlink(destination, join(cwd, 'linked.ts'))
|
|
37
|
+
const before = await captureTree(cwd)
|
|
38
|
+
|
|
39
|
+
await writeFile(destination, 'changed external content')
|
|
40
|
+
expect(changes(before, await captureTree(cwd))).toEqual([])
|
|
41
|
+
await writeFile(join(cwd, 'a.ts'), 'changed content')
|
|
42
|
+
const mode = (await lstat(join(cwd, 'b.ts'))).mode
|
|
43
|
+
await chmod(join(cwd, 'b.ts'), mode ^ 0o100)
|
|
44
|
+
await rm(join(cwd, 'linked.ts'))
|
|
45
|
+
await symlink(join(outside, 'missing.ts'), join(cwd, 'linked.ts'))
|
|
46
|
+
await writeFile(join(cwd, 'new.ts'), 'new content')
|
|
47
|
+
|
|
48
|
+
const after = await captureTree(cwd)
|
|
49
|
+
expect(changes(before, after)).toEqual(['a.ts', 'b.ts', 'linked.ts', 'new.ts'])
|
|
50
|
+
expect(treeVersion(after)).not.toBe(treeVersion(before))
|
|
51
|
+
expect(treeVersion(new Map([...after].reverse()))).not.toBe(treeVersion(after))
|
|
52
|
+
await rm(join(cwd, 'a.ts'))
|
|
53
|
+
expect(changes(after, await captureTree(cwd))).toEqual(['a.ts'])
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
/** Exercise scope precedence, path inspection and text detection independently. */
|
|
57
|
+
test('source inventory accepts unfamiliar names and rejects unsafe paths, binary and non-file targets', async () => {
|
|
58
|
+
const { cwd } = await fixture()
|
|
59
|
+
const outside = await temporary()
|
|
60
|
+
expect(isSource('src/main.ts')).toBe(true)
|
|
61
|
+
expect(isSource('types.d.mts')).toBe(true)
|
|
62
|
+
expect(isSource('bin/outil')).toBe(true)
|
|
63
|
+
for (const file of ['docs/main.ts', 'node_modules/main.ts', 'README.md']) {
|
|
64
|
+
expect(isSource(file)).toBe(false)
|
|
65
|
+
}
|
|
66
|
+
expect(isSource('README.md', ['README.md'])).toBe(true)
|
|
67
|
+
expect(isSource('README.md', ['README.md'], ['*.md'])).toBe(false)
|
|
68
|
+
expect(isSource('docs/main.ts', ['docs/main.ts'])).toBe(false)
|
|
69
|
+
for (const file of ['/absolute.ts', '../escape.ts', './a.ts', 'src//a.ts', 'src/../a.ts', 'src\\a.ts', 'docs/main.ts']) {
|
|
70
|
+
await expect(isTextSource(cwd, file)).rejects.toThrow(`Invalid source path: ${file}`)
|
|
71
|
+
}
|
|
72
|
+
await expect(isTextSource(cwd, 'a.ts')).resolves.toBe(true)
|
|
73
|
+
await expect(isTextSource(cwd, 'missing/new.ts')).resolves.toBe(false)
|
|
74
|
+
expect(await lstat(join(cwd, 'missing')).catch(() => null)).toBeNull()
|
|
75
|
+
|
|
76
|
+
await symlink(outside, join(cwd, 'linked'), 'junction')
|
|
77
|
+
await expect(isTextSource(cwd, 'linked/new.ts')).rejects.toThrow('Symlink source paths are unsupported: linked/new.ts')
|
|
78
|
+
await mkdir(join(cwd, 'directory.ts'))
|
|
79
|
+
await expect(isTextSource(cwd, 'directory.ts')).resolves.toBe(false)
|
|
80
|
+
await writeFile(join(cwd, 'archive.dsl'), Buffer.from([0xff, 0, 0x80]))
|
|
81
|
+
await expect(isTextSource(cwd, 'archive.dsl')).resolves.toBe(false)
|
|
82
|
+
await writeFile(join(cwd, '构建'), Buffer.from('\uFEFFrun job\r\n', 'utf16le'))
|
|
83
|
+
await expect(isTextSource(cwd, '构建')).resolves.toBe(true)
|
|
84
|
+
await writeFile(join(cwd, '构建'), Buffer.from([0xfe, 0xff, 0x00, 0x61]))
|
|
85
|
+
await expect(isTextSource(cwd, '构建')).resolves.toBe(true)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
/** Ensure a replaced ancestor is an actual failure rather than an apparently missing tracked file. */
|
|
89
|
+
test.skipIf(process.platform === 'win32')('snapshot and source validation propagate non-ENOENT filesystem failures', async () => {
|
|
90
|
+
const { cwd } = await fixture()
|
|
91
|
+
await mkdir(join(cwd, 'parent'))
|
|
92
|
+
await writeFile(join(cwd, 'parent', 'child.ts'), 'tracked content')
|
|
93
|
+
await exec('git', ['-C', cwd, 'add', 'parent/child.ts'])
|
|
94
|
+
await rm(join(cwd, 'parent'), { recursive: true })
|
|
95
|
+
await writeFile(join(cwd, 'parent'), 'replaced ancestor')
|
|
96
|
+
|
|
97
|
+
await expect(isTextSource(cwd, 'parent/child.ts')).rejects.toMatchObject({ code: 'ENOTDIR' })
|
|
98
|
+
await expect(captureTree(cwd)).rejects.toMatchObject({ code: 'ENOTDIR' })
|
|
99
|
+
})
|
package/tsconfig.json
ADDED