|
1 | 1 | import { afterEach, describe, expect, test } from "bun:test" |
2 | | -import { chmodSync, existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs" |
| 2 | +import { chmodSync, existsSync, mkdtempSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "fs" |
3 | 3 | import { tmpdir } from "os" |
4 | 4 | import { join } from "path" |
5 | 5 | import { spawnSync } from "child_process" |
@@ -86,4 +86,62 @@ exit 0 |
86 | 86 | expect(existsSync(logPath)).toBe(true) |
87 | 87 | expect(readFileSync(logPath, "utf-8")).toContain("extraction ok") |
88 | 88 | }) |
| 89 | + |
| 90 | + test("suppresses terminal maintenance logs when OPENCODE_MEMORY_TERMINAL_LOG=0", () => { |
| 91 | + const root = makeTempRoot() |
| 92 | + const fakeBin = join(root, "bin") |
| 93 | + const homeDir = join(root, "home") |
| 94 | + const tmpDir = join(root, "tmp") |
| 95 | + const claudeDir = join(root, "claude") |
| 96 | + |
| 97 | + mkdirSync(fakeBin, { recursive: true }) |
| 98 | + mkdirSync(homeDir, { recursive: true }) |
| 99 | + mkdirSync(tmpDir, { recursive: true }) |
| 100 | + mkdirSync(claudeDir, { recursive: true }) |
| 101 | + |
| 102 | + writeExecutable( |
| 103 | + join(fakeBin, "opencode"), |
| 104 | + `#!/usr/bin/env bash |
| 105 | +set -euo pipefail |
| 106 | +if [ "\${1:-}" = "session" ] && [ "\${2:-}" = "list" ]; then |
| 107 | + echo '[{"id":"ses_test_456","time":{"updated":1,"created":1}}]' |
| 108 | + exit 0 |
| 109 | +fi |
| 110 | +if [ "\${1:-}" = "run" ]; then |
| 111 | + echo "extraction ok" |
| 112 | + exit 0 |
| 113 | +fi |
| 114 | +if [ "\${1:-}" = "--help" ]; then |
| 115 | + echo "fake help" |
| 116 | + exit 0 |
| 117 | +fi |
| 118 | +exit 0 |
| 119 | +`, |
| 120 | + ) |
| 121 | + |
| 122 | + const result = spawnSync("bash", [scriptPath, "--help"], { |
| 123 | + cwd: root, |
| 124 | + encoding: "utf-8", |
| 125 | + env: { |
| 126 | + ...process.env, |
| 127 | + PATH: `${fakeBin}:${process.env.PATH ?? ""}`, |
| 128 | + HOME: homeDir, |
| 129 | + TMPDIR: tmpDir, |
| 130 | + CLAUDE_CONFIG_DIR: claudeDir, |
| 131 | + OPENCODE_MEMORY_FOREGROUND: "1", |
| 132 | + OPENCODE_MEMORY_TERMINAL_LOG: "0", |
| 133 | + OPENCODE_MEMORY_AUTODREAM: "0", |
| 134 | + }, |
| 135 | + }) |
| 136 | + |
| 137 | + expect(result.status).toBe(0) |
| 138 | + expect(result.stderr).toBe("") |
| 139 | + |
| 140 | + const logDir = join(root, "tmp", "opencode-memory-logs") |
| 141 | + const logFiles = readdirSync(logDir) |
| 142 | + expect(logFiles).toHaveLength(1) |
| 143 | + |
| 144 | + const logPath = join(logDir, logFiles[0] ?? "") |
| 145 | + expect(readFileSync(logPath, "utf-8")).toContain("extraction ok") |
| 146 | + }) |
89 | 147 | }) |
0 commit comments