oneworks 0.0.0 → 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present One Works contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,109 @@
1
+ import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
2
+ import { tmpdir } from 'node:os'
3
+ import path from 'node:path'
4
+
5
+ import { afterEach, describe, expect, it, vi } from 'vitest'
6
+
7
+ import {
8
+ readCliAdapterPackageRequest,
9
+ resolveAdapterPackageName,
10
+ resolveCliAdapterPackageDir
11
+ } from '../src/adapter-package-cache'
12
+
13
+ const tempDirs: string[] = []
14
+
15
+ afterEach(async () => {
16
+ vi.unstubAllEnvs()
17
+ await Promise.all(tempDirs.splice(0).map(dir => rm(dir, { recursive: true, force: true })))
18
+ })
19
+
20
+ const writeCachedAdapterPackage = async (homeDir: string, packageName: string, version: string) => {
21
+ const cacheDir = path.join(
22
+ homeDir,
23
+ '.oneworks/bootstrap/adapter-packages',
24
+ packageName.replace(/^@/, '').replace(/[\\/]/g, '__'),
25
+ version
26
+ )
27
+ const packageDir = path.join(cacheDir, 'node_modules', ...packageName.split('/'))
28
+ await mkdir(packageDir, { recursive: true })
29
+ await writeFile(
30
+ path.join(packageDir, 'package.json'),
31
+ JSON.stringify({ name: packageName, version }, null, 2)
32
+ )
33
+ return cacheDir
34
+ }
35
+
36
+ describe('bootstrap adapter package cache', () => {
37
+ it('normalizes built-in adapter ids to adapter package names', () => {
38
+ expect(resolveAdapterPackageName('codex')).toBe('@oneworks/adapter-codex')
39
+ expect(resolveAdapterPackageName('adapter-codex')).toBe('@oneworks/adapter-codex')
40
+ expect(resolveAdapterPackageName('claude')).toBe('@oneworks/adapter-claude-code')
41
+ expect(resolveAdapterPackageName('@acme/custom-adapter')).toBe('@acme/custom-adapter')
42
+ })
43
+
44
+ it('reads adapter requests from forwarded CLI arguments', () => {
45
+ expect(readCliAdapterPackageRequest(['--adapter', 'codex'], '0.1.0-alpha.0')).toEqual({
46
+ adapter: 'codex',
47
+ cliVersion: '0.1.0-alpha.0'
48
+ })
49
+ expect(readCliAdapterPackageRequest(['-Aadapter-codex@0.132.0'], '0.1.0-alpha.0')).toEqual({
50
+ adapter: 'adapter-codex@0.132.0',
51
+ cliVersion: '0.1.0-alpha.0'
52
+ })
53
+ expect(readCliAdapterPackageRequest(['--resume', 'sess-id'], '0.1.0-alpha.0', 'codex')).toEqual({
54
+ adapter: 'codex',
55
+ cliVersion: '0.1.0-alpha.0'
56
+ })
57
+ })
58
+
59
+ it('resolves an existing user-home adapter package cache before installing', async () => {
60
+ const homeDir = await mkdtemp(path.join(tmpdir(), 'ow-bootstrap-adapter-cache-'))
61
+ tempDirs.push(homeDir)
62
+ vi.stubEnv('__ONEWORKS_PROJECT_REAL_HOME__', homeDir)
63
+
64
+ const cacheDir = await writeCachedAdapterPackage(homeDir, '@oneworks/adapter-codex', '3.3.1')
65
+
66
+ await expect(
67
+ resolveCliAdapterPackageDir({
68
+ adapter: 'codex',
69
+ cliVersion: '3.2.4-alpha.5'
70
+ })
71
+ ).resolves.toBe(cacheDir)
72
+ })
73
+
74
+ it('uses the highest cached adapter package that satisfies the CLI semver floor', async () => {
75
+ const homeDir = await mkdtemp(path.join(tmpdir(), 'ow-bootstrap-adapter-cache-'))
76
+ tempDirs.push(homeDir)
77
+ vi.stubEnv('__ONEWORKS_PROJECT_REAL_HOME__', homeDir)
78
+
79
+ await writeCachedAdapterPackage(homeDir, '@oneworks/adapter-codex', '3.3.9')
80
+ const compatibleCacheDir = await writeCachedAdapterPackage(homeDir, '@oneworks/adapter-codex', '3.4.1')
81
+ await writeCachedAdapterPackage(homeDir, '@oneworks/adapter-codex', '3.5.0-beta')
82
+ await writeCachedAdapterPackage(homeDir, '@oneworks/adapter-codex', '4.0.0')
83
+
84
+ await expect(
85
+ resolveCliAdapterPackageDir({
86
+ adapter: 'codex',
87
+ cliVersion: '3.4.0-rc'
88
+ })
89
+ ).resolves.toBe(compatibleCacheDir)
90
+ })
91
+
92
+ it('preserves prerelease CLI versions when matching adapter package caches', async () => {
93
+ const homeDir = await mkdtemp(path.join(tmpdir(), 'ow-bootstrap-adapter-cache-'))
94
+ tempDirs.push(homeDir)
95
+ vi.stubEnv('__ONEWORKS_PROJECT_REAL_HOME__', homeDir)
96
+
97
+ await writeCachedAdapterPackage(homeDir, '@oneworks/adapter-codex', '3.3.9')
98
+ const prereleaseCacheDir = await writeCachedAdapterPackage(homeDir, '@oneworks/adapter-codex', '3.4.0-rc')
99
+ await writeCachedAdapterPackage(homeDir, '@oneworks/adapter-codex', '3.5.0-beta')
100
+ await writeCachedAdapterPackage(homeDir, '@oneworks/adapter-codex', '4.0.0')
101
+
102
+ await expect(
103
+ resolveCliAdapterPackageDir({
104
+ adapter: 'codex',
105
+ cliVersion: '3.4.0-rc'
106
+ })
107
+ ).resolves.toBe(prereleaseCacheDir)
108
+ })
109
+ })
@@ -0,0 +1,210 @@
1
+ import { describe, expect, it, vi } from 'vitest'
2
+
3
+ import { createBootstrapCli, routeBootstrapCommand } from '../src/program'
4
+
5
+ describe('bootstrap cli', () => {
6
+ it('routes reserved web command to the web package', () => {
7
+ expect(routeBootstrapCommand('web', ['--port', '8787'])).toEqual({
8
+ commandName: 'oneworks-web',
9
+ forwardedArgs: ['--port', '8787'],
10
+ kind: 'package',
11
+ packageName: '@oneworks/web'
12
+ })
13
+ })
14
+
15
+ it('routes app to the desktop launcher', () => {
16
+ expect(routeBootstrapCommand('app', [])).toEqual({
17
+ forwardedArgs: [],
18
+ kind: 'desktop',
19
+ persistInstallMode: false
20
+ })
21
+ })
22
+
23
+ it('routes app cache to the desktop launcher in cache mode', () => {
24
+ expect(routeBootstrapCommand('app', ['cache'])).toEqual({
25
+ forwardedArgs: [],
26
+ installMode: 'cache',
27
+ kind: 'desktop',
28
+ persistInstallMode: true
29
+ })
30
+ })
31
+
32
+ it('routes app --no-cache to the desktop launcher in user mode', () => {
33
+ expect(routeBootstrapCommand('app', ['--no-cache'])).toEqual({
34
+ forwardedArgs: [],
35
+ installMode: 'user',
36
+ kind: 'desktop',
37
+ persistInstallMode: true
38
+ })
39
+ })
40
+
41
+ it('routes runtime package checks', () => {
42
+ expect(routeBootstrapCommand('runtime', ['check', 'cli', '--json'])).toEqual({
43
+ action: 'check',
44
+ json: true,
45
+ kind: 'runtime-package',
46
+ target: 'cli'
47
+ })
48
+ })
49
+
50
+ it('routes runtime package versions from target selectors', () => {
51
+ expect(routeBootstrapCommand('runtime', ['check', 'server@1.2.3', '--json'])).toEqual({
52
+ action: 'check',
53
+ json: true,
54
+ kind: 'runtime-package',
55
+ target: 'server',
56
+ version: '1.2.3'
57
+ })
58
+ })
59
+
60
+ it('routes runtime package versions from flags', () => {
61
+ expect(routeBootstrapCommand('runtime', ['install', 'client', '--version=2.3.4'])).toEqual({
62
+ action: 'install',
63
+ json: false,
64
+ kind: 'runtime-package',
65
+ target: 'client',
66
+ version: '2.3.4'
67
+ })
68
+ })
69
+
70
+ it('routes unknown commands through the CLI package', () => {
71
+ expect(routeBootstrapCommand('hello', [])).toEqual({
72
+ commandName: 'oneworks',
73
+ forwardedArgs: ['hello'],
74
+ kind: 'package',
75
+ packageName: '@oneworks/cli'
76
+ })
77
+ })
78
+
79
+ it('dispatches the desktop launcher for app', async () => {
80
+ const launchDesktopApp = vi.fn(async () => {})
81
+ const launchInstalledPackage = vi.fn(async () => 0)
82
+ const cli = createBootstrapCli({
83
+ launchDesktopApp,
84
+ launchInstalledPackage
85
+ })
86
+
87
+ await cli.parseAsync(['node', 'oneworks', 'app'])
88
+
89
+ expect(launchDesktopApp).toHaveBeenCalledWith({
90
+ forwardedArgs: [],
91
+ installMode: undefined,
92
+ persistInstallMode: false
93
+ })
94
+ expect(launchInstalledPackage).not.toHaveBeenCalled()
95
+ })
96
+
97
+ it('dispatches cache mode for app cache', async () => {
98
+ const launchDesktopApp = vi.fn(async () => {})
99
+ const launchInstalledPackage = vi.fn(async () => 0)
100
+ const cli = createBootstrapCli({
101
+ launchDesktopApp,
102
+ launchInstalledPackage
103
+ })
104
+
105
+ await cli.parseAsync(['node', 'oneworks', 'app', 'cache'])
106
+
107
+ expect(launchDesktopApp).toHaveBeenCalledWith({
108
+ forwardedArgs: [],
109
+ installMode: 'cache',
110
+ persistInstallMode: true
111
+ })
112
+ expect(launchInstalledPackage).not.toHaveBeenCalled()
113
+ })
114
+
115
+ it('dispatches forwarded commands through the CLI package', async () => {
116
+ const launchDesktopApp = vi.fn(async () => {})
117
+ const launchInstalledPackage = vi.fn(async () => 0)
118
+ const cli = createBootstrapCli({
119
+ launchDesktopApp,
120
+ launchInstalledPackage
121
+ })
122
+
123
+ await cli.parseAsync(['node', 'oneworks', 'hello'])
124
+
125
+ expect(launchInstalledPackage).toHaveBeenCalledWith({
126
+ packageName: '@oneworks/cli',
127
+ commandName: 'oneworks',
128
+ forwardedArgs: ['hello']
129
+ })
130
+ expect(launchDesktopApp).not.toHaveBeenCalled()
131
+ })
132
+
133
+ it('dispatches runtime package installation without launching a runtime', async () => {
134
+ const writeSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true)
135
+ const checkRuntimePackage = vi.fn(async () => {
136
+ throw new Error('unexpected check')
137
+ })
138
+ const installRuntimePackage = vi.fn(async () => ({
139
+ installed: true,
140
+ installedVersion: '1.2.3',
141
+ latestInstalled: true,
142
+ latestVersion: '1.2.3',
143
+ packageName: '@oneworks/cli',
144
+ target: 'cli' as const,
145
+ updateAvailable: false
146
+ }))
147
+ const launchDesktopApp = vi.fn(async () => {})
148
+ const launchInstalledPackage = vi.fn(async () => 0)
149
+ const cli = createBootstrapCli({
150
+ checkRuntimePackage,
151
+ installRuntimePackage,
152
+ launchDesktopApp,
153
+ launchInstalledPackage
154
+ })
155
+
156
+ await cli.parseAsync(['node', 'oneworks', 'runtime', 'install', 'cli', '--json'])
157
+
158
+ expect(installRuntimePackage).toHaveBeenCalledWith('cli')
159
+ expect(checkRuntimePackage).not.toHaveBeenCalled()
160
+ expect(launchDesktopApp).not.toHaveBeenCalled()
161
+ expect(launchInstalledPackage).not.toHaveBeenCalled()
162
+ expect(writeSpy).toHaveBeenCalledWith(expect.stringContaining('"packageName":"@oneworks/cli"'))
163
+ })
164
+
165
+ it('dispatches runtime package installation with a requested version', async () => {
166
+ const writeSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true)
167
+ const checkRuntimePackage = vi.fn(async () => {
168
+ throw new Error('unexpected check')
169
+ })
170
+ const installRuntimePackage = vi.fn(async () => ({
171
+ installed: true,
172
+ installedVersion: '1.2.3',
173
+ latestInstalled: true,
174
+ latestVersion: '1.2.3',
175
+ packageName: '@oneworks/cli',
176
+ requestedVersion: '1.2.3',
177
+ target: 'cli' as const,
178
+ updateAvailable: false
179
+ }))
180
+ const cli = createBootstrapCli({
181
+ checkRuntimePackage,
182
+ installRuntimePackage,
183
+ launchDesktopApp: vi.fn(async () => {}),
184
+ launchInstalledPackage: vi.fn(async () => 0)
185
+ })
186
+
187
+ await cli.parseAsync(['node', 'oneworks', 'runtime', 'install', 'cli@1.2.3', '--json'])
188
+
189
+ expect(installRuntimePackage).toHaveBeenCalledWith('cli', { version: '1.2.3' })
190
+ expect(checkRuntimePackage).not.toHaveBeenCalled()
191
+ expect(writeSpy).toHaveBeenCalledWith(expect.stringContaining('"requestedVersion":"1.2.3"'))
192
+ })
193
+
194
+ it('forwards --help after a routed command', async () => {
195
+ const launchDesktopApp = vi.fn(async () => {})
196
+ const launchInstalledPackage = vi.fn(async () => 0)
197
+ const cli = createBootstrapCli({
198
+ launchDesktopApp,
199
+ launchInstalledPackage
200
+ })
201
+
202
+ await cli.parseAsync(['node', 'oneworks', 'web', '--help'])
203
+
204
+ expect(launchInstalledPackage).toHaveBeenCalledWith({
205
+ packageName: '@oneworks/web',
206
+ commandName: 'oneworks-web',
207
+ forwardedArgs: ['--help']
208
+ })
209
+ })
210
+ })
@@ -0,0 +1,106 @@
1
+ import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
2
+ import os from 'node:os'
3
+ import path from 'node:path'
4
+ import process from 'node:process'
5
+
6
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest'
7
+
8
+ import { __TEST_ONLY__ } from '../src/desktop-app'
9
+
10
+ describe('desktop asset selection', () => {
11
+ const release = {
12
+ tagName: 'pkg/oneworks-desktop/v0.1.7',
13
+ assets: [
14
+ { name: 'oneworks-0.1.7-mac-arm64.zip', url: 'https://example.com/mac-arm64.zip' },
15
+ { name: 'oneworks-0.1.7-linux-x86_64.AppImage', url: 'https://example.com/linux.AppImage' },
16
+ { name: 'oneworks-0.1.7-win-x64.exe', url: 'https://example.com/win.exe' }
17
+ ]
18
+ }
19
+
20
+ it('selects a matching macOS archive', () => {
21
+ expect(__TEST_ONLY__.selectDesktopAsset(release, {
22
+ platform: 'darwin',
23
+ arch: 'arm64'
24
+ })).toEqual(release.assets[0])
25
+ })
26
+
27
+ it('selects a matching Linux AppImage', () => {
28
+ expect(__TEST_ONLY__.selectDesktopAsset(release, {
29
+ platform: 'linux',
30
+ arch: 'x64'
31
+ })).toEqual(release.assets[1])
32
+ })
33
+
34
+ it('selects a matching Windows installer when present', () => {
35
+ expect(__TEST_ONLY__.selectDesktopAsset(release, {
36
+ platform: 'win32',
37
+ arch: 'x64'
38
+ })).toEqual(release.assets[2])
39
+ })
40
+ })
41
+
42
+ describe('desktop install mode resolution', () => {
43
+ const originalRealHome = process.env.__ONEWORKS_PROJECT_REAL_HOME__
44
+ const originalStdinIsTTY = process.stdin.isTTY
45
+ const originalStdoutIsTTY = process.stdout.isTTY
46
+ let tempHomeDir = ''
47
+
48
+ beforeEach(async () => {
49
+ tempHomeDir = await mkdtemp(path.join(os.tmpdir(), 'ow-bootstrap-'))
50
+ process.env.__ONEWORKS_PROJECT_REAL_HOME__ = tempHomeDir
51
+ })
52
+
53
+ afterEach(async () => {
54
+ if (originalRealHome == null) {
55
+ delete process.env.__ONEWORKS_PROJECT_REAL_HOME__
56
+ } else {
57
+ process.env.__ONEWORKS_PROJECT_REAL_HOME__ = originalRealHome
58
+ }
59
+ Object.defineProperty(process.stdin, 'isTTY', { configurable: true, value: originalStdinIsTTY })
60
+ Object.defineProperty(process.stdout, 'isTTY', { configurable: true, value: originalStdoutIsTTY })
61
+ await rm(tempHomeDir, { recursive: true, force: true })
62
+ })
63
+
64
+ it('uses an explicit cache mode without prompting', async () => {
65
+ await expect(__TEST_ONLY__.resolveInstallMode({
66
+ explicitInstallMode: 'cache',
67
+ persistInstallMode: true
68
+ })).resolves.toBe('cache')
69
+ await expect(__TEST_ONLY__.readDesktopPreference()).resolves.toEqual({
70
+ installMode: 'cache'
71
+ })
72
+ })
73
+
74
+ it('uses an explicit user mode and stores it as the default', async () => {
75
+ await expect(__TEST_ONLY__.resolveInstallMode({
76
+ explicitInstallMode: 'user',
77
+ persistInstallMode: true
78
+ })).resolves.toBe('user')
79
+ await expect(__TEST_ONLY__.readDesktopPreference()).resolves.toEqual({
80
+ installMode: 'user'
81
+ })
82
+ })
83
+
84
+ it('defaults to user mode when no tty is available', async () => {
85
+ Object.defineProperty(process.stdin, 'isTTY', { configurable: true, value: false })
86
+ Object.defineProperty(process.stdout, 'isTTY', { configurable: true, value: false })
87
+
88
+ await expect(__TEST_ONLY__.resolveInstallMode({
89
+ explicitInstallMode: undefined,
90
+ persistInstallMode: false
91
+ })).resolves.toBe('user')
92
+ })
93
+
94
+ it('reuses the stored cache preference', async () => {
95
+ await mkdir(path.join(tempHomeDir, '.oneworks', 'bootstrap', 'desktop'), { recursive: true })
96
+ await writeFile(
97
+ path.join(tempHomeDir, '.oneworks', 'bootstrap', 'desktop', 'preferences.json'),
98
+ `${JSON.stringify({ installMode: 'cache' }, null, 2)}\n`
99
+ )
100
+
101
+ await expect(__TEST_ONLY__.resolveInstallMode({
102
+ explicitInstallMode: undefined,
103
+ persistInstallMode: false
104
+ })).resolves.toBe('cache')
105
+ })
106
+ })
@@ -0,0 +1,149 @@
1
+ import { chmod, mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
2
+ import os from 'node:os'
3
+ import path from 'node:path'
4
+ import process from 'node:process'
5
+
6
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
7
+
8
+ import { resolvePackageManagerEnv, resolvePublishedPackageVersion } from '../src/npm-package'
9
+
10
+ describe('bootstrap npm package env', () => {
11
+ const originalCwd = process.cwd()
12
+ const originalPath = process.env.PATH
13
+ let tempDir: string
14
+
15
+ beforeEach(async () => {
16
+ tempDir = await mkdtemp(path.join(os.tmpdir(), 'oneworks-bootstrap-npm-'))
17
+ process.chdir(tempDir)
18
+ vi.restoreAllMocks()
19
+ vi.stubEnv('__ONEWORKS_PROJECT_REAL_HOME__', tempDir)
20
+ vi.stubEnv('ONEWORKS_BOOTSTRAP_DISABLE_BACKGROUND_REFRESH', '1')
21
+ vi.stubEnv('ONEWORKS_BOOTSTRAP_PACKAGE_CACHE_FIRST', undefined)
22
+ vi.stubEnv('ONEWORKS_BOOTSTRAP_PACKAGE_LOOKUP_TIMEOUT_MS', '1000')
23
+ vi.stubEnv('NPM_CONFIG_USERCONFIG', undefined)
24
+ vi.stubEnv('npm_config_userconfig', undefined)
25
+ })
26
+
27
+ afterEach(async () => {
28
+ process.chdir(originalCwd)
29
+ vi.restoreAllMocks()
30
+ vi.unstubAllEnvs()
31
+ await rm(tempDir, { force: true, recursive: true })
32
+ })
33
+
34
+ const installFakeNpm = async () => {
35
+ const binDir = path.join(tempDir, 'bin')
36
+ const npmBin = path.join(binDir, 'npm')
37
+ await mkdir(binDir, { recursive: true })
38
+ await writeFile(
39
+ npmBin,
40
+ `#!/usr/bin/env node
41
+ const delay = Number.parseInt(process.env.ONEWORKS_TEST_NPM_VIEW_DELAY_MS || '0', 10)
42
+ const version = process.env.ONEWORKS_TEST_NPM_VIEW_VERSION || '1.0.0'
43
+ if (process.argv[2] === 'view') {
44
+ setTimeout(() => {
45
+ process.stdout.write(JSON.stringify(version) + '\\n')
46
+ }, delay)
47
+ } else {
48
+ process.exit(1)
49
+ }
50
+ `,
51
+ 'utf8'
52
+ )
53
+ await chmod(npmBin, 0o755)
54
+ vi.stubEnv('PATH', [binDir, originalPath].filter(Boolean).join(path.delimiter))
55
+ }
56
+
57
+ const writeCachedPackage = async (packageName: string, version: string) => {
58
+ const sanitizedName = packageName.replace(/^@/, '').replace(/[\\/]/g, '__')
59
+ const packageDir = path.join(
60
+ tempDir,
61
+ '.oneworks/bootstrap/npm',
62
+ sanitizedName,
63
+ version,
64
+ 'node_modules',
65
+ ...packageName.split('/')
66
+ )
67
+ await mkdir(packageDir, { recursive: true })
68
+ await writeFile(
69
+ path.join(packageDir, 'package.json'),
70
+ JSON.stringify({ name: packageName, version }),
71
+ 'utf8'
72
+ )
73
+ }
74
+
75
+ it('uses the project npmrc as npm userconfig', async () => {
76
+ const projectNpmrc = path.join(process.cwd(), '.npmrc')
77
+ await writeFile(projectNpmrc, '@oneworks:registry=https://registry.npmjs.org/\n')
78
+
79
+ const env = resolvePackageManagerEnv()
80
+
81
+ expect(env.NPM_CONFIG_USERCONFIG).toBe(projectNpmrc)
82
+ expect(env.npm_config_userconfig).toBe(projectNpmrc)
83
+ expect(env.NPM_CONFIG_REPLACE_REGISTRY_HOST).toBe('never')
84
+ expect(env.npm_config_replace_registry_host).toBe('never')
85
+ })
86
+
87
+ it('keeps an explicit npm userconfig override', async () => {
88
+ const explicitUserConfig = path.join(tempDir, 'custom.npmrc')
89
+ await writeFile(path.join(tempDir, '.npmrc'), '@oneworks:registry=https://registry.npmjs.org/\n')
90
+ vi.stubEnv('NPM_CONFIG_USERCONFIG', explicitUserConfig)
91
+
92
+ const env = resolvePackageManagerEnv()
93
+
94
+ expect(env.NPM_CONFIG_USERCONFIG).toBe(explicitUserConfig)
95
+ expect(env.npm_config_userconfig).toBe(explicitUserConfig)
96
+ })
97
+
98
+ it('records fast npm view results for later launches', async () => {
99
+ await installFakeNpm()
100
+ vi.stubEnv('ONEWORKS_BOOTSTRAP_PACKAGE_CACHE_FIRST', '0')
101
+ vi.stubEnv('ONEWORKS_TEST_NPM_VIEW_VERSION', '1.2.3')
102
+
103
+ await expect(resolvePublishedPackageVersion('@scope/pkg')).resolves.toBe('1.2.3')
104
+
105
+ vi.stubEnv('ONEWORKS_TEST_NPM_VIEW_VERSION', '2.0.0')
106
+ await expect(resolvePublishedPackageVersion('@scope/pkg')).resolves.toBe('2.0.0')
107
+ })
108
+
109
+ it('uses cached package versions without blocking on npm view by default', async () => {
110
+ await installFakeNpm()
111
+ vi.stubEnv('ONEWORKS_TEST_NPM_VIEW_VERSION', '1.2.3')
112
+
113
+ await expect(resolvePublishedPackageVersion('@scope/pkg')).resolves.toBe('1.2.3')
114
+
115
+ vi.stubEnv('ONEWORKS_TEST_NPM_VIEW_VERSION', '9.9.9')
116
+ vi.stubEnv('ONEWORKS_TEST_NPM_VIEW_DELAY_MS', '200')
117
+ await expect(resolvePublishedPackageVersion('@scope/pkg')).resolves.toBe('1.2.3')
118
+ })
119
+
120
+ it('uses installed package cache before npm view when no metadata exists', async () => {
121
+ await writeCachedPackage('@scope/pkg', '4.5.6')
122
+
123
+ await expect(resolvePublishedPackageVersion('@scope/pkg')).resolves.toBe('4.5.6')
124
+ })
125
+
126
+ it('uses cached package versions when npm view exceeds the startup budget in refresh-first mode', async () => {
127
+ await installFakeNpm()
128
+ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
129
+ vi.stubEnv('ONEWORKS_BOOTSTRAP_PACKAGE_CACHE_FIRST', '0')
130
+ vi.stubEnv('ONEWORKS_BOOTSTRAP_PACKAGE_LOOKUP_TIMEOUT_MS', '20')
131
+ vi.stubEnv('ONEWORKS_TEST_NPM_VIEW_VERSION', '1.2.3')
132
+
133
+ await expect(resolvePublishedPackageVersion('@scope/pkg')).resolves.toBe('1.2.3')
134
+
135
+ vi.stubEnv('ONEWORKS_TEST_NPM_VIEW_VERSION', '9.9.9')
136
+ vi.stubEnv('ONEWORKS_TEST_NPM_VIEW_DELAY_MS', '200')
137
+ await expect(resolvePublishedPackageVersion('@scope/pkg')).resolves.toBe('1.2.3')
138
+
139
+ expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('timed out after 20ms'))
140
+ })
141
+
142
+ it('waits for npm view when no cached package version exists yet', async () => {
143
+ await installFakeNpm()
144
+ vi.stubEnv('ONEWORKS_TEST_NPM_VIEW_VERSION', '3.0.0')
145
+ vi.stubEnv('ONEWORKS_TEST_NPM_VIEW_DELAY_MS', '50')
146
+
147
+ await expect(resolvePublishedPackageVersion('@scope/uncached')).resolves.toBe('3.0.0')
148
+ })
149
+ })
@@ -0,0 +1,23 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest'
2
+
3
+ import { shouldResolveCliAdapterPackage } from '../src/package-launcher'
4
+
5
+ afterEach(() => {
6
+ vi.unstubAllEnvs()
7
+ })
8
+
9
+ describe('bootstrap package launcher', () => {
10
+ it('resolves adapter packages when the loader only defaulted CLI package dir to bootstrap itself', () => {
11
+ vi.stubEnv('__ONEWORKS_PROJECT_PACKAGE_DIR__', '/runtime/bootstrap')
12
+ vi.stubEnv('__ONEWORKS_PROJECT_CLI_PACKAGE_DIR__', '/runtime/bootstrap')
13
+
14
+ expect(shouldResolveCliAdapterPackage()).toBe(true)
15
+ })
16
+
17
+ it('preserves an explicit external CLI package dir', () => {
18
+ vi.stubEnv('__ONEWORKS_PROJECT_PACKAGE_DIR__', '/runtime/bootstrap')
19
+ vi.stubEnv('__ONEWORKS_PROJECT_CLI_PACKAGE_DIR__', '/runtime/adapter-cache')
20
+
21
+ expect(shouldResolveCliAdapterPackage()).toBe(false)
22
+ })
23
+ })