mirror of
https://github.com/NoeFabris/opencode-antigravity-auth.git
synced 2026-05-13 15:46:05 +00:00
hive: merge 01-add-baseline-tests-for-current-behavior--harness
This commit is contained in:
69
src/plugin/debug.test.ts
Normal file
69
src/plugin/debug.test.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { mkdtempSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
|
||||
|
||||
vi.mock("./storage", () => ({
|
||||
ensureGitignoreSync: vi.fn(),
|
||||
}))
|
||||
|
||||
function createTmpDir(prefix: string): string {
|
||||
return mkdtempSync(join(tmpdir(), prefix))
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
vi.stubEnv("OPENCODE_ANTIGRAVITY_DEBUG", "")
|
||||
vi.stubEnv("OPENCODE_ANTIGRAVITY_DEBUG_TUI", "")
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs()
|
||||
})
|
||||
|
||||
describe("debug.ts baseline coupling", () => {
|
||||
it("keeps TUI debug disabled when debug=false and debug_tui=true", async () => {
|
||||
const configDir = createTmpDir("antigravity-debug-config-")
|
||||
const logDir = createTmpDir("antigravity-debug-logs-")
|
||||
vi.stubEnv("XDG_CONFIG_HOME", configDir)
|
||||
|
||||
const { DEFAULT_CONFIG } = await import("./config")
|
||||
const { initializeDebug, isDebugEnabled, isDebugTuiEnabled, getLogFilePath } = await import("./debug")
|
||||
|
||||
initializeDebug({ ...DEFAULT_CONFIG, debug: false, debug_tui: true, log_dir: logDir })
|
||||
|
||||
expect(isDebugEnabled()).toBe(false)
|
||||
expect(isDebugTuiEnabled()).toBe(false)
|
||||
expect(getLogFilePath()).toBeUndefined()
|
||||
})
|
||||
|
||||
it("enables file debug only when debug=true and debug_tui=false", async () => {
|
||||
const configDir = createTmpDir("antigravity-debug-config-")
|
||||
const logDir = createTmpDir("antigravity-debug-logs-")
|
||||
vi.stubEnv("XDG_CONFIG_HOME", configDir)
|
||||
|
||||
const { DEFAULT_CONFIG } = await import("./config")
|
||||
const { initializeDebug, isDebugEnabled, isDebugTuiEnabled, getLogFilePath } = await import("./debug")
|
||||
|
||||
initializeDebug({ ...DEFAULT_CONFIG, debug: true, debug_tui: false, log_dir: logDir })
|
||||
|
||||
expect(isDebugEnabled()).toBe(true)
|
||||
expect(isDebugTuiEnabled()).toBe(false)
|
||||
expect(getLogFilePath()).toBeTruthy()
|
||||
})
|
||||
|
||||
it("enables both file and TUI debug when debug=true and debug_tui=true", async () => {
|
||||
const configDir = createTmpDir("antigravity-debug-config-")
|
||||
const logDir = createTmpDir("antigravity-debug-logs-")
|
||||
vi.stubEnv("XDG_CONFIG_HOME", configDir)
|
||||
|
||||
const { DEFAULT_CONFIG } = await import("./config")
|
||||
const { initializeDebug, isDebugEnabled, isDebugTuiEnabled, getLogFilePath } = await import("./debug")
|
||||
|
||||
initializeDebug({ ...DEFAULT_CONFIG, debug: true, debug_tui: true, log_dir: logDir })
|
||||
|
||||
expect(isDebugEnabled()).toBe(true)
|
||||
expect(isDebugTuiEnabled()).toBe(true)
|
||||
expect(getLogFilePath()).toBeTruthy()
|
||||
})
|
||||
})
|
||||
74
src/plugin/logger.test.ts
Normal file
74
src/plugin/logger.test.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { mkdtempSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
|
||||
import type { PluginClient } from "./types"
|
||||
|
||||
vi.mock("./storage", () => ({
|
||||
ensureGitignoreSync: vi.fn(),
|
||||
}))
|
||||
|
||||
function createTmpDir(prefix: string): string {
|
||||
return mkdtempSync(join(tmpdir(), prefix))
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
vi.stubEnv("OPENCODE_ANTIGRAVITY_DEBUG", "")
|
||||
vi.stubEnv("OPENCODE_ANTIGRAVITY_DEBUG_TUI", "")
|
||||
vi.stubEnv("OPENCODE_ANTIGRAVITY_CONSOLE_LOG", "")
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs()
|
||||
})
|
||||
|
||||
describe("logger.ts baseline sink routing", () => {
|
||||
async function runLoggerWithFlags(debug: boolean, debugTui: boolean): Promise<{ appLog: ReturnType<typeof vi.fn> }> {
|
||||
const configDir = createTmpDir("antigravity-logger-config-")
|
||||
const logDir = createTmpDir("antigravity-logger-logs-")
|
||||
vi.stubEnv("XDG_CONFIG_HOME", configDir)
|
||||
|
||||
const { DEFAULT_CONFIG } = await import("./config")
|
||||
const { initializeDebug } = await import("./debug")
|
||||
const { initLogger, createLogger } = await import("./logger")
|
||||
|
||||
initializeDebug({ ...DEFAULT_CONFIG, debug, debug_tui: debugTui, log_dir: logDir })
|
||||
|
||||
const appLog = vi.fn().mockResolvedValue(undefined)
|
||||
const client = {
|
||||
app: {
|
||||
log: appLog,
|
||||
},
|
||||
}
|
||||
|
||||
initLogger(client as unknown as PluginClient)
|
||||
const logger = createLogger("baseline")
|
||||
logger.debug("testing baseline routing", { debug, debugTui })
|
||||
|
||||
return { appLog }
|
||||
}
|
||||
|
||||
it("does not emit TUI logs when debug=false and debug_tui=true", async () => {
|
||||
const { appLog } = await runLoggerWithFlags(false, true)
|
||||
expect(appLog).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it("does not emit TUI logs when debug=true and debug_tui=false", async () => {
|
||||
const { appLog } = await runLoggerWithFlags(true, false)
|
||||
expect(appLog).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it("emits TUI logs when debug=true and debug_tui=true", async () => {
|
||||
const { appLog } = await runLoggerWithFlags(true, true)
|
||||
expect(appLog).toHaveBeenCalledTimes(1)
|
||||
expect(appLog).toHaveBeenCalledWith({
|
||||
body: {
|
||||
service: "antigravity.baseline",
|
||||
level: "debug",
|
||||
message: "testing baseline routing",
|
||||
extra: { debug: true, debugTui: true },
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,7 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { mkdtempSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, it, expect, vi } from "vitest";
|
||||
import {
|
||||
prepareAntigravityRequest,
|
||||
transformAntigravityResponse,
|
||||
@@ -6,6 +9,8 @@ import {
|
||||
isGenerativeLanguageRequest,
|
||||
__testExports,
|
||||
} from "./request";
|
||||
import { DEFAULT_CONFIG, initRuntimeConfig } from "./config";
|
||||
import { DEBUG_MESSAGE_PREFIX, initializeDebug } from "./debug";
|
||||
import type { SignatureStore, ThoughtBuffer, StreamingCallbacks, StreamingOptions } from "./core/streaming/types";
|
||||
|
||||
const {
|
||||
@@ -53,6 +58,14 @@ const defaultCallbacks: StreamingCallbacks = {};
|
||||
const defaultOptions: StreamingOptions = {};
|
||||
const defaultDebugState = { injected: false };
|
||||
|
||||
function createTestDir(prefix: string): string {
|
||||
return mkdtempSync(join(tmpdir(), prefix));
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
describe("request.ts", () => {
|
||||
describe("getPluginSessionId", () => {
|
||||
it("returns consistent session ID across calls", () => {
|
||||
@@ -911,6 +924,112 @@ it("removes x-api-key header", () => {
|
||||
});
|
||||
|
||||
describe("transformAntigravityResponse", () => {
|
||||
const createSuccessResponse = () =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
response: {
|
||||
candidates: [
|
||||
{
|
||||
content: {
|
||||
parts: [{ text: "hello" }],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
{
|
||||
status: 200,
|
||||
headers: { "content-type": "application/json" },
|
||||
},
|
||||
);
|
||||
|
||||
it("does not inject debug thinking when debug=false and debug_tui=true", async () => {
|
||||
const configDir = createTestDir("antigravity-request-config-");
|
||||
const logDir = createTestDir("antigravity-request-logs-");
|
||||
vi.stubEnv("XDG_CONFIG_HOME", configDir);
|
||||
|
||||
initializeDebug({ ...DEFAULT_CONFIG, debug: false, debug_tui: true, log_dir: logDir });
|
||||
initRuntimeConfig({ ...DEFAULT_CONFIG, keep_thinking: false, log_dir: logDir });
|
||||
|
||||
const transformed = await transformAntigravityResponse(
|
||||
createSuccessResponse(),
|
||||
false,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
["ThinkingResolution: debug line"],
|
||||
);
|
||||
|
||||
const body = JSON.parse(await transformed.text());
|
||||
expect(body.candidates[0].content.parts).toEqual([{ text: "hello" }]);
|
||||
expect(body.candidates[0].reasoning_content).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not inject debug thinking when debug=true and debug_tui=false", async () => {
|
||||
const configDir = createTestDir("antigravity-request-config-");
|
||||
const logDir = createTestDir("antigravity-request-logs-");
|
||||
vi.stubEnv("XDG_CONFIG_HOME", configDir);
|
||||
|
||||
initializeDebug({ ...DEFAULT_CONFIG, debug: true, debug_tui: false, log_dir: logDir });
|
||||
initRuntimeConfig({ ...DEFAULT_CONFIG, keep_thinking: false, log_dir: logDir });
|
||||
|
||||
const transformed = await transformAntigravityResponse(
|
||||
createSuccessResponse(),
|
||||
false,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
["ThinkingResolution: debug line"],
|
||||
);
|
||||
|
||||
const body = JSON.parse(await transformed.text());
|
||||
expect(body.candidates[0].content.parts).toEqual([{ text: "hello" }]);
|
||||
expect(body.candidates[0].reasoning_content).toBeUndefined();
|
||||
});
|
||||
|
||||
it("injects debug thinking only when debug=true and debug_tui=true", async () => {
|
||||
const configDir = createTestDir("antigravity-request-config-");
|
||||
const logDir = createTestDir("antigravity-request-logs-");
|
||||
vi.stubEnv("XDG_CONFIG_HOME", configDir);
|
||||
|
||||
initializeDebug({ ...DEFAULT_CONFIG, debug: true, debug_tui: true, log_dir: logDir });
|
||||
initRuntimeConfig({ ...DEFAULT_CONFIG, keep_thinking: false, log_dir: logDir });
|
||||
|
||||
const transformed = await transformAntigravityResponse(
|
||||
createSuccessResponse(),
|
||||
false,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
["ThinkingResolution: debug line"],
|
||||
);
|
||||
|
||||
const body = JSON.parse(await transformed.text());
|
||||
expect(body.candidates[0].content.parts).toHaveLength(2);
|
||||
expect(body.candidates[0].content.parts[0].type).toBe("reasoning");
|
||||
expect(body.candidates[0].content.parts[0].text).toContain(DEBUG_MESSAGE_PREFIX);
|
||||
expect(body.candidates[0].content.parts[0].text).toContain("ThinkingResolution: debug line");
|
||||
expect(body.candidates[0].reasoning_content).toContain(DEBUG_MESSAGE_PREFIX);
|
||||
});
|
||||
|
||||
it("does not misclassify generic INVALID_ARGUMENT as thinking recovery from debug metadata", async () => {
|
||||
const response = new Response(
|
||||
JSON.stringify({
|
||||
|
||||
Reference in New Issue
Block a user