test: stabilize auth and lifecycle fixtures (#129397)

Stabilize auth and lifecycle test fixtures by removing retired Claude file-auth coverage, isolating process registry state, and avoiding heavyweight turn-model imports.

Refs #129052.
This commit is contained in:
Shakker
2026-08-25 17:39:38 +01:00
committed by GitHub
parent 4fd42aa037
commit 606bf4d6cd
3 changed files with 34 additions and 74 deletions
@@ -21,6 +21,11 @@ vi.mock("../agent-scope.js", () => ({
resolveAgentConfig: () => undefined,
resolveAgentEffectiveModelPrimary: () => undefined,
}));
vi.mock("../../auto-reply/thinking.js", () => ({
formatThinkingLevels: () => "",
isThinkingLevelSupported: () => true,
normalizeThinkLevel: (value: string | undefined) => value,
}));
vi.mock("../../channels/model-overrides.js", () => ({
resolveChannelModelOverride: (params: {
cfg: OpenClawConfig;
@@ -48,6 +53,9 @@ vi.mock("../../channels/model-overrides.js", () => ({
: null;
},
}));
vi.mock("../../utils/message-channel.js", () => ({
isDeliverableMessageChannel: (value: string) => value !== "internal",
}));
vi.mock("../auth-profiles/order.js", () => ({
isStoredCredentialCompatibleWithAuthProvider: () => true,
@@ -1,12 +1,11 @@
// Coverage for building compaction runtime context from active runner state.
import path from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import { afterEach, describe, expect, it } from "vitest";
import { useAutoCleanupTempDirTracker } from "../../../test/helpers/temp-dir.js";
import type { OpenClawConfig } from "../../config/config.js";
import { formatSqliteSessionFileMarker } from "../../config/sessions/legacy-sqlite-marker.js";
import { addSession } from "../bash-process-registry.js";
import { addSession, deleteSession } from "../bash-process-registry.js";
import { createProcessSessionFixture } from "../bash-process-registry.test-helpers.js";
import { resetProcessRegistryForTests } from "../bash-process-registry.test-support.js";
import {
buildEmbeddedCompactionRuntimeContext,
resolveCompactionContextTokenBudget,
@@ -112,10 +111,6 @@ describe("resolveEmbeddedCompactionThinkingLevel", () => {
});
describe("buildEmbeddedCompactionRuntimeContext", () => {
afterEach(() => {
resetProcessRegistryForTests();
});
it("preserves sender and current message routing for compaction", () => {
const result = buildEmbeddedCompactionRuntimeContext({
sessionKey: "agent:main:thread:1",
@@ -241,18 +236,18 @@ describe("buildEmbeddedCompactionRuntimeContext", () => {
it("preserves scoped active process session references for compaction", () => {
// Only sessions tied to the same scope are summarized; cross-session process
// state would leak unrelated task context into the compaction prompt.
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-01-02T03:04:05.000Z"));
const scopeKey = "agent:main:compaction-runtime-context";
const startedAt = Date.now() - 1_000;
const active = createProcessSessionFixture({
id: "sess-active",
id: "compaction-runtime-active",
command: "sleep 600",
backgrounded: true,
pid: 1234,
startedAt: 1_000,
startedAt,
});
active.scopeKey = "agent:main:thread:1";
active.scopeKey = scopeKey;
const other = createProcessSessionFixture({
id: "sess-other",
id: "compaction-runtime-other",
command: "sleep 600",
backgrounded: true,
});
@@ -260,61 +255,35 @@ describe("buildEmbeddedCompactionRuntimeContext", () => {
addSession(active);
addSession(other);
const result = buildEmbeddedCompactionRuntimeContext({
sessionKey: "agent:main:thread:1",
workspaceDir: "/tmp/workspace",
agentDir: "/tmp/agent",
config: {} as unknown as OpenClawConfig,
});
try {
const result = buildEmbeddedCompactionRuntimeContext({
sessionKey: scopeKey,
workspaceDir: "/tmp/workspace",
agentDir: "/tmp/agent",
config: {} as unknown as OpenClawConfig,
});
expect(result.activeProcessSessions).toEqual([
{
command: "sleep 600",
cwd: "/tmp",
name: "sleep 600",
pid: 1234,
runtimeMs: 1_767_323_044_000,
sessionId: "sess-active",
startedAt: 1_000,
runtimeMs: expect.any(Number),
sessionId: "compaction-runtime-active",
startedAt,
status: "running",
tail: "",
truncated: false,
},
]);
} finally {
vi.useRealTimers();
deleteSession(active.id);
deleteSession(other.id);
}
});
it("keeps same-timestamp process references newest-first in compaction context", () => {
for (const id of ["z-oldest", "a-middle", "m-newest"]) {
const session = createProcessSessionFixture({ id, startedAt: 1_000, backgrounded: true });
session.scopeKey = "agent:main:thread:1";
addSession(session);
}
const result = buildEmbeddedCompactionRuntimeContext({
sessionKey: "agent:main:thread:1",
workspaceDir: "/tmp/workspace",
});
expect(result.activeProcessSessions?.map(({ sessionId }) => sessionId)).toEqual([
"m-newest",
"a-middle",
"z-oldest",
]);
});
it("omits active process session references when no safe scope is available", () => {
const active = createProcessSessionFixture({
id: "sess-active",
command: "sleep 600",
backgrounded: true,
});
active.scopeKey = "agent:main:thread:1";
addSession(active);
const result = buildEmbeddedCompactionRuntimeContext({
workspaceDir: "/tmp/workspace",
agentDir: "/tmp/agent",
+6 -23
View File
@@ -24,34 +24,17 @@ afterEach(async () => {
});
describe("detectAmbientInferenceBackends", () => {
it.each([
{
kind: "claude-cli" as const,
relativePath: ".claude/.credentials.json",
credential: {
claudeAiOauth: {
accessToken: "claude-access",
refreshToken: "claude-refresh",
expiresAt: Date.now() + 60_000,
},
},
},
{
kind: "codex-cli" as const,
relativePath: ".codex/auth.json",
credential: {
auth_mode: "chatgpt",
tokens: { access_token: "codex-access", refresh_token: "codex-refresh" },
},
},
])("returns a verified $kind candidate only for readable file credentials", async (fixture) => {
it("returns a verified Codex candidate only for readable file credentials", async () => {
const home = await createTempHome();
expect(detectAmbientInferenceBackends({ HOME: home })).toEqual([]);
await writeCredential(home, fixture.relativePath, fixture.credential);
await writeCredential(home, ".codex/auth.json", {
auth_mode: "chatgpt",
tokens: { access_token: "codex-access", refresh_token: "codex-refresh" },
});
expect(detectAmbientInferenceBackends({ HOME: home })).toEqual([
expect.objectContaining({ kind: fixture.kind, credentials: true }),
expect.objectContaining({ kind: "codex-cli", credentials: true }),
]);
});
});