Skip to content

Commit a14e1ed

Browse files
committed
Fix CI-only permission and plugin loading tests
Update the add-dir permission assertion to match the real absolute home-directory rules produced after the homedir path fix. Also pre-create the isolated XDG directories in the plugin loading e2e so direct opencode boot matches the runtime startup environment and can become healthy in CI. Session: ses_25f529a61ffeoxYPMQFgb5dkpg
1 parent bff02e9 commit a14e1ed

2 files changed

Lines changed: 41 additions & 33 deletions

File tree

cli/src/commands/add-dir.test.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { describe, expect, test } from 'vitest'
44
import fs from 'node:fs'
5+
import os from 'node:os'
56
import path from 'node:path'
67
import {
78
buildAddDirPermissionRules,
@@ -108,40 +109,39 @@ describe('resolveDirectoryPermissionPattern', () => {
108109
})
109110

110111
test('pre-allows common toolchain caches under home with ~ patterns', () => {
112+
const home = os.homedir().replaceAll('\\', '/')
111113
expect(
112114
buildSessionPermissions({
113115
directory: '/Users/me/project',
114116
}).filter((rule) => {
115117
return [
116-
'~/.cache/zig',
117-
'~/.cargo',
118-
'~/.cache/go-build',
119-
'~/go/pkg',
118+
`${home}/.cache/zig`,
119+
`${home}/.cargo`,
120+
`${home}/.cache/go-build`,
121+
`${home}/go/pkg`,
120122
].includes(rule.pattern)
121123
}),
122-
).toMatchInlineSnapshot(`
123-
[
124-
{
125-
"action": "allow",
126-
"pattern": "~/.cache/zig",
127-
"permission": "external_directory",
128-
},
129-
{
130-
"action": "allow",
131-
"pattern": "~/.cargo",
132-
"permission": "external_directory",
133-
},
134-
{
135-
"action": "allow",
136-
"pattern": "~/.cache/go-build",
137-
"permission": "external_directory",
138-
},
139-
{
140-
"action": "allow",
141-
"pattern": "~/go/pkg",
142-
"permission": "external_directory",
143-
},
144-
]
145-
`)
124+
).toEqual([
125+
{
126+
permission: 'external_directory',
127+
pattern: `${home}/.cache/zig`,
128+
action: 'allow',
129+
},
130+
{
131+
permission: 'external_directory',
132+
pattern: `${home}/.cargo`,
133+
action: 'allow',
134+
},
135+
{
136+
permission: 'external_directory',
137+
pattern: `${home}/.cache/go-build`,
138+
action: 'allow',
139+
},
140+
{
141+
permission: 'external_directory',
142+
pattern: `${home}/go/pkg`,
143+
action: 'allow',
144+
},
145+
])
146146
})
147147
})

cli/src/kimaki-opencode-plugin-loading.e2e.test.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ test(
4747
const pluginPath = new URL('../src/kimaki-opencode-plugin.ts', import.meta.url).href
4848
const stderrLines: string[] = []
4949
const isolatedOpencodeRoot = path.join(projectDir, 'opencode-test-home')
50+
const xdgDirectories = {
51+
OPENCODE_CONFIG_DIR: path.join(isolatedOpencodeRoot, '.opencode-kimaki'),
52+
XDG_CONFIG_HOME: path.join(isolatedOpencodeRoot, '.config'),
53+
XDG_DATA_HOME: path.join(isolatedOpencodeRoot, '.local', 'share'),
54+
XDG_CACHE_HOME: path.join(isolatedOpencodeRoot, '.cache'),
55+
XDG_STATE_HOME: path.join(isolatedOpencodeRoot, '.local', 'state'),
56+
}
57+
58+
fs.mkdirSync(isolatedOpencodeRoot, { recursive: true })
59+
Object.values(xdgDirectories).forEach((directory) => {
60+
fs.mkdirSync(directory, { recursive: true })
61+
})
5062

5163
const {
5264
command,
@@ -70,11 +82,7 @@ test(
7082
plugin: [pluginPath],
7183
}),
7284
OPENCODE_TEST_HOME: isolatedOpencodeRoot,
73-
OPENCODE_CONFIG_DIR: path.join(isolatedOpencodeRoot, '.opencode-kimaki'),
74-
XDG_CONFIG_HOME: path.join(isolatedOpencodeRoot, '.config'),
75-
XDG_DATA_HOME: path.join(isolatedOpencodeRoot, '.local', 'share'),
76-
XDG_CACHE_HOME: path.join(isolatedOpencodeRoot, '.cache'),
77-
XDG_STATE_HOME: path.join(isolatedOpencodeRoot, '.local', 'state'),
85+
...xdgDirectories,
7886
},
7987
})
8088

0 commit comments

Comments
 (0)