Skip to content

Commit 847c7e8

Browse files
committed
test(build-tools-readiness): add liveness check and extract callable helper
1 parent 64dbc30 commit 847c7e8

1 file changed

Lines changed: 17 additions & 24 deletions

File tree

‎src/core/task/__tests__/build-tools-readiness.integration.spec.ts‎

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ describe.each([
4343
}
4444
}
4545

46+
function callable(result: Awaited<ReturnType<typeof buildNativeToolsArrayWithRestrictions>>) {
47+
return includeAllToolsWithRestrictions ? result.allowedFunctionNames : toolNames(result.tools)
48+
}
49+
4650
it("uses the task context and cwd without leaking readiness between workspaces", async () => {
4751
const options = makeOptions()
4852
const ready = makeManager({ isFeatureEnabled: true, isFeatureConfigured: true, isInitialized: true })
@@ -55,9 +59,7 @@ describe.each([
5559

5660
const first = await buildNativeToolsArrayWithRestrictions(options)
5761
expect(CodeIndexManagerRegistry.getOrCreate).toHaveBeenLastCalledWith(options.provider.context, "/tasks/ready")
58-
expect(includeAllToolsWithRestrictions ? first.allowedFunctionNames : toolNames(first.tools)).toContain(
59-
tools.codebase_search,
60-
)
62+
expect(callable(first)).toContain(tools.codebase_search)
6163

6264
const other = await buildNativeToolsArrayWithRestrictions({ ...options, cwd: "/tasks/unready" })
6365
expect(CodeIndexManagerRegistry.getOrCreate).toHaveBeenLastCalledWith(
@@ -73,12 +75,13 @@ describe.each([
7375
expect(other.allowedFunctionNames).toBeUndefined()
7476
expect(toolNames(other.tools)).not.toContain(tools.codebase_search)
7577
}
78+
for (const tool of ordinaryReadTools) {
79+
expect(callable(other)).toContain(tool)
80+
}
7681

7782
const restored = await buildNativeToolsArrayWithRestrictions(options)
7883
expect(CodeIndexManagerRegistry.getOrCreate).toHaveBeenLastCalledWith(options.provider.context, "/tasks/ready")
79-
expect(includeAllToolsWithRestrictions ? restored.allowedFunctionNames : toolNames(restored.tools)).toContain(
80-
tools.codebase_search,
81-
)
84+
expect(callable(restored)).toContain(tools.codebase_search)
8285
expect(CodeIndexManagerRegistry.getOrCreate).toHaveBeenCalledTimes(3)
8386
})
8487

@@ -95,9 +98,7 @@ describe.each([
9598
expect(toolNames(result.tools)).not.toContain(tools.codebase_search)
9699
}
97100
for (const tool of ordinaryReadTools) {
98-
expect(includeAllToolsWithRestrictions ? result.allowedFunctionNames : toolNames(result.tools)).toContain(
99-
tool,
100-
)
101+
expect(callable(result)).toContain(tool)
101102
}
102103
})
103104

@@ -109,9 +110,7 @@ describe.each([
109110
vi.mocked(CodeIndexManagerRegistry.getOrCreate).mockReturnValue(makeManager(flags))
110111

111112
const initial = await buildNativeToolsArrayWithRestrictions(options)
112-
expect(includeAllToolsWithRestrictions ? initial.allowedFunctionNames : toolNames(initial.tools)).toContain(
113-
tools.codebase_search,
114-
)
113+
expect(callable(initial)).toContain(tools.codebase_search)
115114

116115
flags[flag] = false
117116
const unavailable = await buildNativeToolsArrayWithRestrictions(options)
@@ -124,16 +123,12 @@ describe.each([
124123
expect(toolNames(unavailable.tools)).not.toContain(tools.codebase_search)
125124
}
126125
for (const tool of ordinaryReadTools) {
127-
expect(
128-
includeAllToolsWithRestrictions ? unavailable.allowedFunctionNames : toolNames(unavailable.tools),
129-
).toContain(tool)
126+
expect(callable(unavailable)).toContain(tool)
130127
}
131128

132129
flags[flag] = true
133130
const recovered = await buildNativeToolsArrayWithRestrictions(options)
134-
expect(
135-
includeAllToolsWithRestrictions ? recovered.allowedFunctionNames : toolNames(recovered.tools),
136-
).toContain(tools.codebase_search)
131+
expect(callable(recovered)).toContain(tools.codebase_search)
137132
},
138133
)
139134

@@ -153,11 +148,11 @@ describe.each([
153148
} else {
154149
expect(result.allowedFunctionNames).toBeUndefined()
155150
}
156-
const callable = includeAllToolsWithRestrictions ? result.allowedFunctionNames : toolNames(result.tools)
151+
const callableSet = callable(result)
157152
for (const tool of [tools.codebase_search, ...ordinaryReadTools]) {
158-
expect(callable).not.toContain(tool)
153+
expect(callableSet).not.toContain(tool)
159154
}
160-
expect(callable).toContain(tools.execute_command)
155+
expect(callableSet).toContain(tools.execute_command)
161156
})
162157

163158
it("honors disabledTools with a ready manager without disabling ordinary read tools", async () => {
@@ -178,9 +173,7 @@ describe.each([
178173
expect(toolNames(result.tools)).not.toContain(tools.codebase_search)
179174
}
180175
for (const tool of ordinaryReadTools) {
181-
expect(includeAllToolsWithRestrictions ? result.allowedFunctionNames : toolNames(result.tools)).toContain(
182-
tool,
183-
)
176+
expect(callable(result)).toContain(tool)
184177
}
185178
})
186179
})

0 commit comments

Comments
 (0)