diff --git a/src/agents/env-context.test.ts b/src/agents/env-context.test.ts new file mode 100644 index 00000000..ea863167 --- /dev/null +++ b/src/agents/env-context.test.ts @@ -0,0 +1,40 @@ +/// + +import { describe, test, expect } from "bun:test" +import { createEnvContext } from "./env-context" + +describe("createEnvContext", () => { + test("returns omo-env block with date, timezone, and locale", () => { + // #given - no setup needed + + // #when + const result = createEnvContext() + + // #then + expect(result).toContain("") + expect(result).toContain("") + expect(result).toContain("Current date:") + expect(result).toContain("Timezone:") + expect(result).toContain("Locale:") + }) + + test("does not include time with seconds precision to preserve token cache", () => { + // #given - seconds-precision time changes every second, breaking cache on every request + + // #when + const result = createEnvContext() + + // #then - no HH:MM:SS pattern anywhere in the output + expect(result).not.toMatch(/\d{1,2}:\d{2}:\d{2}/) + }) + + test("does not include Current time field", () => { + // #given - time field (even without seconds) changes every minute, degrading cache + + // #when + const result = createEnvContext() + + // #then - time field entirely removed; date-level precision is sufficient + expect(result).not.toContain("Current time:") + }) +}) diff --git a/src/agents/env-context.ts b/src/agents/env-context.ts index 262886ca..4dc7412a 100644 --- a/src/agents/env-context.ts +++ b/src/agents/env-context.ts @@ -1,5 +1,5 @@ /** - * Creates OmO-specific environment context (time, timezone, locale). + * Creates OmO-specific environment context (timezone, locale). * Note: Working directory, platform, and date are already provided by OpenCode's system.ts, * so we only include fields that OpenCode doesn't provide to avoid duplication. * See: https://github.com/code-yeongyu/oh-my-opencode/issues/379 @@ -16,17 +16,9 @@ export function createEnvContext(): string { day: "numeric", }) - const timeStr = now.toLocaleTimeString(locale, { - hour: "2-digit", - minute: "2-digit", - second: "2-digit", - hour12: true, - }) - return ` Current date: ${dateStr} - Current time: ${timeStr} Timezone: ${timezone} Locale: ${locale} `