GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): substitute empty for missing config file references (#55388) · matglas/opencode@c458ad7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/core
    • src/config
      • variable.ts
    • test
      • config
        • config.test.ts
      • location-layer.test.ts
      • session-move.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/core/src/config/variable.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/config/variable.ts
+17-21Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ type ParseSource =
1919

2020
type SubstituteInput = ParseSource & {
2121
text: string
22-
missing?: "error" | "empty"
2322
env?: Record<string, string>
2423
}
2524

@@ -56,27 +55,24 @@ const substituteFiles = Effect.fnUntraced(function* (input: SubstituteInput, tex
5655
const filePath = token.slice("{file:".length, -1)
5756
const expandedPath = filePath.startsWith("~/") ? path.join(os.homedir(), filePath.slice(2)) : filePath
5857
const resolvedPath = path.isAbsolute(expandedPath) ? expandedPath : path.resolve(configDir, expandedPath)
59-
const fileContent = yield* fs.readFileString(resolvedPath).pipe(
60-
Effect.catch((error) => {
61-
if (input.missing === "empty") return Effect.succeed("")
58+
const fileContent = yield* fs
59+
.readFileStringSafe(resolvedPath)
60+
.pipe(
61+
Effect.mapError(
62+
(error) =>
63+
new InvalidError({ path: configSource, message: `bad file reference: "${token}"` }, { cause: error }),
64+
),
65+
)
66+
// Like a missing {env:VAR}, a missing or unreadable file substitutes empty so one stale secret
67+
// reference cannot take down every Location that loads this config.
68+
if (fileContent === undefined)
69+
yield* Effect.logWarning("config file reference is missing or unreadable", {
70+
source: configSource,
71+
reference: token,
72+
path: resolvedPath,
73+
})
6274

63-
const message = `bad file reference: "${token}"`
64-
return Effect.fail(
65-
new InvalidError(
66-
{
67-
path: configSource,
68-
message:
69-
error._tag === "PlatformError" && error.reason._tag === "NotFound"
70-
? `${message} ${resolvedPath} does not exist`
71-
: message,
72-
},
73-
{ cause: error },
74-
),
75-
)
76-
}),
77-
)
78-
79-
out += JSON.stringify(fileContent.trim()).slice(1, -1)
75+
out += JSON.stringify((fileContent ?? "").trim()).slice(1, -1)
8076
cursor = index + token.length
8177
}
8278

Collapse file

‎packages/core/test/config/config.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/config/config.test.ts
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ describe("Config", () => {
13061306
fs.writeFile(
13071307
path.join(tmp.path, "opencode.jsonc"),
13081308
`{
1309-
// Ignored reference: {file:missing.txt}
1309+
// Ignored reference: {file:.}
13101310
"username": "user-{env:OPENCODE_TEST_MISSING}",
13111311
"mcp": {
13121312
"servers": {
@@ -1315,7 +1315,8 @@ describe("Config", () => {
13151315
"url": "https://example.com/mcp",
13161316
"headers": {
13171317
"Authorization": "Bearer {env:OPENCODE_TEST_MCP_TOKEN}",
1318-
"X-Token": "{file:token.txt}"
1318+
"X-Token": "{file:token.txt}",
1319+
"X-Missing": "Bearer {file:~/.opencode-test-missing/key}"
13191320
}
13201321
}
13211322
}
@@ -1335,6 +1336,7 @@ describe("Config", () => {
13351336
expect(remote.headers).toEqual({
13361337
Authorization: "Bearer secret",
13371338
"X-Token": 'file\n"token"',
1339+
"X-Missing": "Bearer ",
13381340
})
13391341
}).pipe(Effect.provide(testLayer(tmp.path)))
13401342
}),
Collapse file

‎packages/core/test/location-layer.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/location-layer.test.ts
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe("LocationServiceMap", () => {
103103
yield* Effect.addFinalizer(() => Effect.promise(() => fs.chmod(directory, 0o755)))
104104
}
105105
if (failure === "config reference") {
106-
yield* Effect.promise(() => fs.mkdir(directory))
106+
yield* Effect.promise(() => fs.mkdir(path.join(directory, "username.txt"), { recursive: true }))
107107
yield* Effect.promise(() =>
108108
fs.writeFile(path.join(directory, "opencode.json"), JSON.stringify({ username: "{file:username.txt}" })),
109109
)
@@ -124,6 +124,7 @@ describe("LocationServiceMap", () => {
124124
}
125125
if (failure === "permissions") yield* Effect.promise(() => fs.chmod(directory, 0o755))
126126
if (failure === "config reference") {
127+
yield* Effect.promise(() => fs.rm(path.join(directory, "username.txt"), { recursive: true }))
127128
yield* Effect.promise(() => fs.writeFile(path.join(directory, "username.txt"), "test-user"))
128129
}
129130
expect((yield* Effect.promise(() => fs.stat(directory))).isDirectory()).toBe(true)
@@ -147,7 +148,7 @@ describe("LocationServiceMap", () => {
147148
const locations = yield* LocationServiceMap.Service
148149
if (failure === "file") yield* Effect.promise(() => fs.writeFile(directory, "file"))
149150
if (failure === "config reference") {
150-
yield* Effect.promise(() => fs.mkdir(directory))
151+
yield* Effect.promise(() => fs.mkdir(path.join(directory, "username.txt"), { recursive: true }))
151152
yield* Effect.promise(() =>
152153
fs.writeFile(path.join(directory, "opencode.json"), JSON.stringify({ username: "{file:username.txt}" })),
153154
)
@@ -165,6 +166,7 @@ describe("LocationServiceMap", () => {
165166
if (failure === "file") yield* Effect.promise(() => fs.rm(directory))
166167
if (failure !== "config reference") yield* Effect.promise(() => fs.mkdir(directory))
167168
if (failure === "config reference") {
169+
yield* Effect.promise(() => fs.rm(path.join(directory, "username.txt"), { recursive: true }))
168170
yield* Effect.promise(() => fs.writeFile(path.join(directory, "username.txt"), "test-user"))
169171
}
170172
const repaired = yield* locations.contextEffect(ref)
Collapse file

‎packages/core/test/session-move.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/session-move.test.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe("Session.move", () => {
215215
yield* Effect.promise(() => Promise.all([mkdir(source), mkdir(destination)]))
216216
if (broken)
217217
yield* Effect.promise(() =>
218-
Bun.write(path.join(source, "opencode.json"), JSON.stringify({ instructions: ["{file:./missing.txt}"] })),
218+
Bun.write(path.join(source, "opencode.json"), JSON.stringify({ instructions: ["{file:.}"] })),
219219
)
220220
const session = yield* Session.Service
221221
const execution = yield* SessionExecution.Service
@@ -271,7 +271,7 @@ describe("Session.move", () => {
271271
const source = Location.Ref.make({ directory: AbsolutePath.make(path.join(tmp.path, "source")) })
272272
const destination = AbsolutePath.make(path.join(tmp.path, "destination"))
273273
yield* Effect.promise(() => Promise.all([mkdir(source.directory), mkdir(destination)]))
274-
const config = JSON.stringify({ instructions: ["{file:./missing.txt}"] })
274+
const config = JSON.stringify({ instructions: ["{file:.}"] })
275275
if (!broken) yield* Effect.promise(() => Bun.write(path.join(source.directory, "opencode.json"), config))
276276
const selectedID = Session.ID.create()
277277
const replacements: LayerNode.Replacements = [

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.