Skip to content

Commit 0817eb7

Browse files
authored
Merge branch 'main' into fix/three-simple-bugs
2 parents 098563d + 01f355c commit 0817eb7

31 files changed

Lines changed: 3009 additions & 15 deletions

‎.github/meta/commit.txt‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
release: v0.5.11
1+
fix: remove flaky `setTimeout` in todo bus event test
22

3-
Update README changelog to reflect releases v0.5.1 through v0.5.11.
4-
Previous README only listed up to v0.5.0, missing 10 versions of features
5-
including `check` CLI, skill management, session tracing, Codespaces support,
6-
impact analysis, Snowflake Cortex, MCP auto-discovery, and more.
3+
`Bus.publish` is synchronous — the event is delivered immediately,
4+
no 50ms delay needed. Removes resource contention risk in parallel CI.
75

86
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { describe, test, expect, beforeEach } from "bun:test"
2+
import { bufferLog, getRecentDbtLogs, clearDbtLogs } from "../src/log-buffer"
3+
4+
describe("dbt log-buffer", () => {
5+
beforeEach(() => {
6+
clearDbtLogs()
7+
})
8+
9+
test("buffers log messages in insertion order", () => {
10+
bufferLog("first")
11+
bufferLog("second")
12+
bufferLog("third")
13+
expect(getRecentDbtLogs()).toEqual(["first", "second", "third"])
14+
})
15+
16+
test("evicts oldest entries when buffer exceeds 100", () => {
17+
for (let i = 0; i < 105; i++) {
18+
bufferLog(`msg-${i}`)
19+
}
20+
const logs = getRecentDbtLogs()
21+
expect(logs).toHaveLength(100)
22+
expect(logs[0]).toBe("msg-5")
23+
expect(logs[99]).toBe("msg-104")
24+
})
25+
26+
test("clearDbtLogs empties the buffer", () => {
27+
bufferLog("something")
28+
clearDbtLogs()
29+
expect(getRecentDbtLogs()).toEqual([])
30+
})
31+
32+
test("getRecentDbtLogs returns a copy, not a reference", () => {
33+
bufferLog("original")
34+
const copy = getRecentDbtLogs()
35+
copy.push("injected")
36+
expect(getRecentDbtLogs()).toEqual(["original"])
37+
})
38+
39+
test("handles empty buffer", () => {
40+
expect(getRecentDbtLogs()).toEqual([])
41+
})
42+
43+
test("buffer stays at exactly 100 after repeated overflow", () => {
44+
for (let i = 0; i < 200; i++) {
45+
bufferLog(`msg-${i}`)
46+
}
47+
expect(getRecentDbtLogs()).toHaveLength(100)
48+
expect(getRecentDbtLogs()[0]).toBe("msg-100")
49+
expect(getRecentDbtLogs()[99]).toBe("msg-199")
50+
})
51+
})

‎packages/opencode/src/altimate/tools/altimate-core-check.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const AltimateCoreCheckTool = Tool.define("altimate_core_check", {
5757
},
5858
})
5959

60-
function formatCheckTitle(data: Record<string, any>): string {
60+
export function formatCheckTitle(data: Record<string, any>): string {
6161
const parts: string[] = []
6262
if (!data.validation?.valid) parts.push("validation errors")
6363
if (!data.lint?.clean) parts.push(`${data.lint?.findings?.length ?? 0} lint findings`)
@@ -66,14 +66,17 @@ function formatCheckTitle(data: Record<string, any>): string {
6666
return parts.length ? parts.join(", ") : "PASS"
6767
}
6868

69-
function formatCheck(data: Record<string, any>): string {
69+
export function formatCheck(data: Record<string, any>): string {
7070
const lines: string[] = []
7171

7272
lines.push("=== Validation ===")
7373
if (data.validation?.valid) {
7474
lines.push("Valid SQL.")
7575
} else {
76-
lines.push(`Invalid: ${data.validation?.errors?.map((e: any) => e.message).join("; ") ?? "unknown"}`)
76+
const validationMessages = (data.validation?.errors ?? [])
77+
.map((e: any) => (typeof e === "string" ? e : e?.message))
78+
.filter(Boolean)
79+
lines.push(`Invalid: ${validationMessages.join("; ") || "unknown"}`)
7780
}
7881

7982
lines.push("\n=== Lint ===")

‎packages/opencode/src/altimate/tools/altimate-core-equivalence.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const AltimateCoreEquivalenceTool = Tool.define("altimate_core_equivalenc
5252
...(error && { error }),
5353
...(findings.length > 0 && { findings }),
5454
},
55-
output: formatEquivalence(data),
55+
output: formatEquivalence(isRealFailure ? { ...data, error } : data),
5656
}
5757
} catch (e) {
5858
const msg = e instanceof Error ? e.message : String(e)
@@ -65,17 +65,17 @@ export const AltimateCoreEquivalenceTool = Tool.define("altimate_core_equivalenc
6565
},
6666
})
6767

68-
function extractEquivalenceErrors(data: Record<string, any>): string | undefined {
68+
export function extractEquivalenceErrors(data: Record<string, any>): string | undefined {
6969
if (Array.isArray(data.validation_errors) && data.validation_errors.length > 0) {
7070
const msgs = data.validation_errors
71-
.map((e: any) => (typeof e === "string" ? e : (e.message ?? String(e))))
71+
.map((e: any) => (typeof e === "string" ? e : (e?.message ?? String(e))))
7272
.filter(Boolean)
7373
return msgs.length > 0 ? msgs.join("; ") : undefined
7474
}
7575
return undefined
7676
}
7777

78-
function formatEquivalence(data: Record<string, any>): string {
78+
export function formatEquivalence(data: Record<string, any>): string {
7979
if (data.error) return `Error: ${data.error}`
8080
const lines: string[] = []
8181
lines.push(data.equivalent ? "Queries are semantically equivalent." : "Queries produce different results.")

‎packages/opencode/src/altimate/tools/altimate-core-semantics.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ export const AltimateCoreSemanticsTool = Tool.define("altimate_core_semantics",
6161
},
6262
})
6363

64-
function extractSemanticsErrors(data: Record<string, any>): string | undefined {
64+
export function extractSemanticsErrors(data: Record<string, any>): string | undefined {
6565
if (Array.isArray(data.validation_errors) && data.validation_errors.length > 0) {
6666
const msgs = data.validation_errors
67-
.map((e: any) => (typeof e === "string" ? e : (e.message ?? String(e))))
67+
.map((e: any) => (typeof e === "string" ? e : (e?.message ?? String(e))))
6868
.filter(Boolean)
6969
return msgs.length > 0 ? msgs.join("; ") : undefined
7070
}
7171
return undefined
7272
}
7373

74-
function formatSemantics(data: Record<string, any>): string {
74+
export function formatSemantics(data: Record<string, any>): string {
7575
if (data.error) return `Error: ${data.error}`
7676
if (data.valid) return "No semantic issues found."
7777
const lines = ["Semantic issues:\n"]

‎packages/opencode/test/agent/agent.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,3 +810,52 @@ test("analyst prompt contains /data-viz skill", async () => {
810810
},
811811
})
812812
})
813+
814+
// --- .env read protection tests ---
815+
816+
test("builder agent asks for .env file reads but allows regular files", async () => {
817+
await using tmp = await tmpdir()
818+
await Instance.provide({
819+
directory: tmp.path,
820+
fn: async () => {
821+
const builder = await Agent.get("builder")
822+
expect(builder).toBeDefined()
823+
// .env files require user approval (security: prevents accidental secret exposure)
824+
expect(PermissionNext.evaluate("read", ".env", builder!.permission).action).toBe("ask")
825+
expect(PermissionNext.evaluate("read", ".env.local", builder!.permission).action).toBe("ask")
826+
expect(PermissionNext.evaluate("read", ".env.production", builder!.permission).action).toBe("ask")
827+
expect(PermissionNext.evaluate("read", "config/.env.staging", builder!.permission).action).toBe("ask")
828+
// Regular files are allowed without prompting
829+
expect(PermissionNext.evaluate("read", "src/index.ts", builder!.permission).action).toBe("allow")
830+
expect(PermissionNext.evaluate("read", "package.json", builder!.permission).action).toBe("allow")
831+
// .env.example is explicitly allowed (safe to share)
832+
expect(PermissionNext.evaluate("read", ".env.example", builder!.permission).action).toBe("allow")
833+
},
834+
})
835+
})
836+
837+
// --- analyst agent write denial tests ---
838+
839+
test("analyst agent denies file modification and todo tools", async () => {
840+
await using tmp = await tmpdir()
841+
await Instance.provide({
842+
directory: tmp.path,
843+
fn: async () => {
844+
const analyst = await Agent.get("analyst")
845+
expect(analyst).toBeDefined()
846+
// Analyst is read-only — file modification tools should be denied.
847+
// The analyst config starts with "*": "deny" then selectively allows
848+
// read-only tools. edit/write/todowrite are not in the allow list,
849+
// so they fall through to the catch-all deny.
850+
expect(evalPerm(analyst, "edit")).toBe("deny")
851+
expect(evalPerm(analyst, "write")).toBe("deny")
852+
expect(evalPerm(analyst, "todowrite")).toBe("deny")
853+
expect(evalPerm(analyst, "todoread")).toBe("deny")
854+
// Read operations are explicitly allowed after the "*": "deny" base,
855+
// so last-match-wins produces "allow"
856+
expect(evalPerm(analyst, "read")).toBe("allow")
857+
expect(evalPerm(analyst, "grep")).toBe("allow")
858+
expect(evalPerm(analyst, "glob")).toBe("allow")
859+
},
860+
})
861+
})
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import { describe, test, expect } from "bun:test"
2+
import { formatCheckTitle, formatCheck } from "../../src/altimate/tools/altimate-core-check"
3+
4+
describe("formatCheckTitle", () => {
5+
test("returns PASS for all-clean result", () => {
6+
const data = {
7+
validation: { valid: true },
8+
lint: { clean: true, findings: [] },
9+
safety: { safe: true },
10+
pii: { findings: [] },
11+
}
12+
expect(formatCheckTitle(data)).toBe("PASS")
13+
})
14+
15+
test("lists all failure categories when everything fails", () => {
16+
const data = {
17+
validation: { valid: false, errors: [{ message: "bad syntax" }] },
18+
lint: { clean: false, findings: [{ rule: "L001" }, { rule: "L002" }] },
19+
safety: { safe: false, threats: [{ type: "injection" }] },
20+
pii: { findings: [{ column: "ssn", category: "SSN" }] },
21+
}
22+
const result = formatCheckTitle(data)
23+
expect(result).toContain("validation errors")
24+
expect(result).toContain("2 lint findings")
25+
expect(result).toContain("safety threats")
26+
expect(result).toContain("PII detected")
27+
})
28+
29+
test("treats missing sections as failures (undefined is falsy)", () => {
30+
// When data is empty, !undefined is true, so each section looks like a failure
31+
const data = {} as Record<string, any>
32+
const result = formatCheckTitle(data)
33+
expect(result).toContain("validation errors")
34+
expect(result).toContain("safety threats")
35+
// lint.findings?.length is undefined, ?? 0 yields "0 lint findings"
36+
expect(result).toContain("0 lint findings")
37+
})
38+
39+
test("shows lint finding count when clean is false but findings is undefined", () => {
40+
const data = {
41+
validation: { valid: true },
42+
lint: { clean: false },
43+
safety: { safe: true },
44+
pii: { findings: [] },
45+
}
46+
// lint.findings?.length is undefined, ?? 0 yields "0 lint findings"
47+
expect(formatCheckTitle(data)).toBe("0 lint findings")
48+
})
49+
50+
test("only shows failing sections, not passing ones", () => {
51+
const data = {
52+
validation: { valid: true },
53+
lint: { clean: true },
54+
safety: { safe: false, threats: [{ type: "drop_table" }] },
55+
pii: { findings: [] },
56+
}
57+
expect(formatCheckTitle(data)).toBe("safety threats")
58+
})
59+
})
60+
61+
describe("formatCheck", () => {
62+
test("formats all-pass result with four sections", () => {
63+
const data = {
64+
validation: { valid: true },
65+
lint: { clean: true },
66+
safety: { safe: true },
67+
pii: { findings: [] },
68+
}
69+
const output = formatCheck(data)
70+
expect(output).toContain("=== Validation ===")
71+
expect(output).toContain("Valid SQL.")
72+
expect(output).toContain("=== Lint ===")
73+
expect(output).toContain("No lint findings.")
74+
expect(output).toContain("=== Safety ===")
75+
expect(output).toContain("Safe — no threats.")
76+
expect(output).toContain("=== PII ===")
77+
expect(output).toContain("No PII detected.")
78+
})
79+
80+
test("formats validation errors", () => {
81+
const data = {
82+
validation: { valid: false, errors: [{ message: "syntax error at line 3" }, { message: "unknown column" }] },
83+
lint: { clean: true },
84+
safety: { safe: true },
85+
pii: {},
86+
}
87+
const output = formatCheck(data)
88+
expect(output).toContain("Invalid: syntax error at line 3; unknown column")
89+
})
90+
91+
test("formats lint findings with severity and rule", () => {
92+
const data = {
93+
validation: { valid: true },
94+
lint: {
95+
clean: false,
96+
findings: [
97+
{ severity: "warning", rule: "L001", message: "Unnecessary whitespace" },
98+
{ severity: "error", rule: "L003", message: "Indentation not consistent" },
99+
],
100+
},
101+
safety: { safe: true },
102+
pii: {},
103+
}
104+
const output = formatCheck(data)
105+
expect(output).toContain("[warning] L001: Unnecessary whitespace")
106+
expect(output).toContain("[error] L003: Indentation not consistent")
107+
})
108+
109+
test("formats safety threats", () => {
110+
const data = {
111+
validation: { valid: true },
112+
lint: { clean: true },
113+
safety: {
114+
safe: false,
115+
threats: [{ severity: "critical", type: "sql_injection", description: "Tautology detected: 1=1" }],
116+
},
117+
pii: {},
118+
}
119+
const output = formatCheck(data)
120+
expect(output).toContain("[critical] sql_injection: Tautology detected: 1=1")
121+
})
122+
123+
test("formats PII findings with column and confidence", () => {
124+
const data = {
125+
validation: { valid: true },
126+
lint: { clean: true },
127+
safety: { safe: true },
128+
pii: {
129+
findings: [
130+
{ column: "ssn", category: "SSN", confidence: "high" },
131+
{ column: "email", category: "EMAIL", confidence: "medium" },
132+
],
133+
},
134+
}
135+
const output = formatCheck(data)
136+
expect(output).toContain("ssn: SSN (high confidence)")
137+
expect(output).toContain("email: EMAIL (medium confidence)")
138+
})
139+
140+
test("handles empty/missing sections without crashing", () => {
141+
const data = {} as Record<string, any>
142+
const output = formatCheck(data)
143+
// Should still produce all four section headers
144+
expect(output).toContain("=== Validation ===")
145+
expect(output).toContain("=== Lint ===")
146+
expect(output).toContain("=== Safety ===")
147+
expect(output).toContain("=== PII ===")
148+
// validation.valid is undefined (falsy) → "Invalid: unknown"
149+
expect(output).toContain("Invalid:")
150+
})
151+
})

0 commit comments

Comments
 (0)