Skip to content

Commit fc75574

Browse files
committed
test(write): set umask to 0o022 for deterministic file permissions
1 parent 58a9991 commit fc75574

1 file changed

Lines changed: 24 additions & 19 deletions

File tree

packages/opencode/test/tool/write.test.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -156,25 +156,30 @@ describe("tool.write", () => {
156156
await using tmp = await tmpdir()
157157
const filepath = path.join(tmp.path, "sensitive.json")
158158

159-
await Instance.provide({
160-
directory: tmp.path,
161-
fn: async () => {
162-
const write = await WriteTool.init()
163-
await write.execute(
164-
{
165-
filePath: filepath,
166-
content: JSON.stringify({ secret: "data" }),
167-
},
168-
ctx,
169-
)
170-
171-
// On Unix systems, check permissions
172-
if (process.platform !== "win32") {
173-
const stats = await fs.stat(filepath)
174-
expect(stats.mode & 0o777).toBe(0o644)
175-
}
176-
},
177-
})
159+
const prevUmask = process.umask(0o022)
160+
try {
161+
await Instance.provide({
162+
directory: tmp.path,
163+
fn: async () => {
164+
const write = await WriteTool.init()
165+
await write.execute(
166+
{
167+
filePath: filepath,
168+
content: JSON.stringify({ secret: "data" }),
169+
},
170+
ctx,
171+
)
172+
173+
// On Unix systems, check permissions
174+
if (process.platform !== "win32") {
175+
const stats = await fs.stat(filepath)
176+
expect(stats.mode & 0o777).toBe(0o644)
177+
}
178+
},
179+
})
180+
} finally {
181+
process.umask(prevUmask)
182+
}
178183
})
179184
})
180185

0 commit comments

Comments
 (0)