test: make unsafe test coercion explicit
Move test coercion out of a hidden global and require each test to import the helper so review tools and runtime scripts can see the unsafe boundary. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -5,6 +5,7 @@ import { tmpdir } from "node:os"
|
||||
import type { RunContext } from "./types"
|
||||
import { _resetForTesting, setSessionAgent } from "../../features/claude-code-session-state"
|
||||
import { writeState as writeRalphLoopState } from "../../hooks/ralph-loop/storage"
|
||||
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
|
||||
|
||||
const testDirs: string[] = []
|
||||
|
||||
@@ -26,7 +27,7 @@ function createTempDir(): string {
|
||||
|
||||
function createMockContext(directory: string): RunContext {
|
||||
return {
|
||||
client: testCoerce<RunContext["client"]>({
|
||||
client: unsafeTestValue<RunContext["client"]>({
|
||||
session: {
|
||||
todo: mock(() => Promise.resolve({ data: [] })),
|
||||
children: mock(() => Promise.resolve({ data: [] })),
|
||||
@@ -155,13 +156,13 @@ describe("checkCompletionConditions continuation coverage", () => {
|
||||
const ctx = createMockContext(directory)
|
||||
ctx.sessionID = "child-session"
|
||||
setSessionAgent("child-session", "atlas")
|
||||
ctx.client.session.get = testCoerce<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.get = unsafeTestValue<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: {
|
||||
id: path.id,
|
||||
parentID: path.id === "child-session" ? "root-session" : undefined,
|
||||
},
|
||||
})))
|
||||
ctx.client.session.messages = testCoerce<RunContext["client"]["session"]["messages"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.messages = unsafeTestValue<RunContext["client"]["session"]["messages"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: path.id === "child-session"
|
||||
? [{ info: { agent: "atlas", providerID: "openai", modelID: "gpt-5.4" } }]
|
||||
: [],
|
||||
@@ -187,13 +188,13 @@ describe("checkCompletionConditions continuation coverage", () => {
|
||||
|
||||
const ctx = createMockContext(directory)
|
||||
ctx.sessionID = "lineage-only-session"
|
||||
ctx.client.session.get = testCoerce<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.get = unsafeTestValue<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: {
|
||||
id: path.id,
|
||||
parentID: path.id === "lineage-only-session" ? "root-session" : undefined,
|
||||
},
|
||||
})))
|
||||
ctx.client.session.messages = testCoerce<RunContext["client"]["session"]["messages"]>(mock(async () => ({ data: [] })))
|
||||
ctx.client.session.messages = unsafeTestValue<RunContext["client"]["session"]["messages"]>(mock(async () => ({ data: [] })))
|
||||
|
||||
const { checkCompletionConditions } = await import("./completion")
|
||||
|
||||
@@ -218,13 +219,13 @@ describe("checkCompletionConditions continuation coverage", () => {
|
||||
|
||||
const ctx = createMockContext(directory)
|
||||
ctx.sessionID = "mismatch-subagent-session"
|
||||
ctx.client.session.get = testCoerce<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.get = unsafeTestValue<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: {
|
||||
id: path.id,
|
||||
parentID: path.id === "mismatch-subagent-session" ? "root-session" : undefined,
|
||||
},
|
||||
})))
|
||||
ctx.client.session.messages = testCoerce<RunContext["client"]["session"]["messages"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.messages = unsafeTestValue<RunContext["client"]["session"]["messages"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: path.id === "mismatch-subagent-session"
|
||||
? [{ info: { agent: "sisyphus-junior", providerID: "openai", modelID: "gpt-5.4" } }]
|
||||
: [],
|
||||
@@ -253,13 +254,13 @@ describe("checkCompletionConditions continuation coverage", () => {
|
||||
|
||||
const ctx = createMockContext(directory)
|
||||
ctx.sessionID = "appended-mismatch-session"
|
||||
ctx.client.session.get = testCoerce<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.get = unsafeTestValue<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: {
|
||||
id: path.id,
|
||||
parentID: path.id === "appended-mismatch-session" ? "root-session" : undefined,
|
||||
},
|
||||
})))
|
||||
ctx.client.session.messages = testCoerce<RunContext["client"]["session"]["messages"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.messages = unsafeTestValue<RunContext["client"]["session"]["messages"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: path.id === "appended-mismatch-session"
|
||||
? [{ info: { agent: "sisyphus-junior", providerID: "openai", modelID: "gpt-5.4" } }]
|
||||
: [],
|
||||
@@ -288,10 +289,10 @@ describe("checkCompletionConditions continuation coverage", () => {
|
||||
|
||||
const ctx = createMockContext(directory)
|
||||
ctx.sessionID = "ses_appended_descendant"
|
||||
ctx.client.session.get = testCoerce<RunContext["client"]["session"]["get"]>(mock(async () => {
|
||||
ctx.client.session.get = unsafeTestValue<RunContext["client"]["session"]["get"]>(mock(async () => {
|
||||
throw new Error("session lookup failed")
|
||||
}))
|
||||
ctx.client.session.messages = testCoerce<RunContext["client"]["session"]["messages"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.messages = unsafeTestValue<RunContext["client"]["session"]["messages"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: path.id === "ses_appended_descendant"
|
||||
? [{ info: { agent: "atlas", providerID: "openai", modelID: "gpt-5.4" } }]
|
||||
: [],
|
||||
@@ -317,7 +318,7 @@ describe("checkCompletionConditions continuation coverage", () => {
|
||||
|
||||
const ctx = createMockContext(directory)
|
||||
ctx.sessionID = "ses_direct_child"
|
||||
ctx.client.session.get = testCoerce<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.get = unsafeTestValue<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: {
|
||||
id: path.id,
|
||||
parentID: path.id === "ses_direct_child" ? "ses_parent" : undefined,
|
||||
@@ -347,7 +348,7 @@ describe("checkCompletionConditions continuation coverage", () => {
|
||||
|
||||
const ctx = createMockContext(directory)
|
||||
ctx.sessionID = "ses_direct_tracked"
|
||||
ctx.client.session.get = testCoerce<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.get = unsafeTestValue<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: {
|
||||
id: path.id,
|
||||
parentID: undefined,
|
||||
@@ -374,7 +375,7 @@ describe("checkCompletionConditions continuation coverage", () => {
|
||||
|
||||
const ctx = createMockContext(directory)
|
||||
ctx.sessionID = "ses_unknown_child"
|
||||
ctx.client.session.get = testCoerce<RunContext["client"]["session"]["get"]>(mock(async () => {
|
||||
ctx.client.session.get = unsafeTestValue<RunContext["client"]["session"]["get"]>(mock(async () => {
|
||||
throw new Error("lineage unavailable")
|
||||
}))
|
||||
|
||||
@@ -401,13 +402,13 @@ describe("checkCompletionConditions continuation coverage", () => {
|
||||
|
||||
const ctx = createMockContext(directory)
|
||||
ctx.sessionID = "ses_direct_child"
|
||||
ctx.client.session.get = testCoerce<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.get = unsafeTestValue<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: {
|
||||
id: path.id,
|
||||
parentID: path.id === "ses_direct_child" ? "ses_root_tracked" : undefined,
|
||||
},
|
||||
})))
|
||||
ctx.client.session.messages = testCoerce<RunContext["client"]["session"]["messages"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.messages = unsafeTestValue<RunContext["client"]["session"]["messages"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: path.id === "ses_direct_child"
|
||||
? [{ info: { agent: "sisyphus-junior", providerID: "openai", modelID: "gpt-5.4" } }]
|
||||
: [],
|
||||
@@ -437,13 +438,13 @@ describe("checkCompletionConditions continuation coverage", () => {
|
||||
const ctx = createMockContext(directory)
|
||||
ctx.sessionID = "ses_child_after_compaction"
|
||||
setSessionAgent("ses_child_after_compaction", "atlas")
|
||||
ctx.client.session.get = testCoerce<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.get = unsafeTestValue<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: {
|
||||
id: path.id,
|
||||
parentID: path.id === "ses_child_after_compaction" ? "root-session" : undefined,
|
||||
},
|
||||
})))
|
||||
ctx.client.session.messages = testCoerce<RunContext["client"]["session"]["messages"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.messages = unsafeTestValue<RunContext["client"]["session"]["messages"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: path.id === "ses_child_after_compaction"
|
||||
? [
|
||||
{ info: { agent: "atlas", providerID: "openai", modelID: "gpt-5.4" } },
|
||||
@@ -472,13 +473,13 @@ describe("checkCompletionConditions continuation coverage", () => {
|
||||
|
||||
const ctx = createMockContext(directory)
|
||||
ctx.sessionID = "ses_sqlite_descendant"
|
||||
ctx.client.session.get = testCoerce<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.get = unsafeTestValue<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: {
|
||||
id: path.id,
|
||||
parentID: path.id === "ses_sqlite_descendant" ? "root-session" : undefined,
|
||||
},
|
||||
})))
|
||||
ctx.client.session.messages = testCoerce<RunContext["client"]["session"]["messages"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.messages = unsafeTestValue<RunContext["client"]["session"]["messages"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: path.id === "ses_sqlite_descendant"
|
||||
? [
|
||||
{ id: "msg_0001", info: { agent: "atlas", providerID: "openai", modelID: "gpt-5.4", time: { created: 100 } } },
|
||||
@@ -512,13 +513,13 @@ describe("checkCompletionConditions continuation coverage", () => {
|
||||
const ctx = createMockContext(directory)
|
||||
ctx.sessionID = "ses_appended_child"
|
||||
setSessionAgent("ses_appended_child", "atlas")
|
||||
ctx.client.session.get = testCoerce<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
ctx.client.session.get = unsafeTestValue<RunContext["client"]["session"]["get"]>(mock(async ({ path }: { path: { id: string } }) => ({
|
||||
data: {
|
||||
id: path.id,
|
||||
parentID: path.id === "ses_appended_child" ? "ses_root_tracked" : undefined,
|
||||
},
|
||||
})))
|
||||
ctx.client.session.messages = testCoerce<RunContext["client"]["session"]["messages"]>(mock(async () => ({ data: [] })))
|
||||
ctx.client.session.messages = unsafeTestValue<RunContext["client"]["session"]["messages"]>(mock(async () => ({ data: [] })))
|
||||
|
||||
const { checkCompletionConditions } = await import("./completion")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user