Files
orca/config/scripts/orcad-linear-sdk-package.test.mjs
T
Neilandthukabjj 7c9bb00622 fix(orcad): ship @linear/sdk with the managed server so Linear works on SSH hosts (#29388)
linear-sdk.ts loads the SDK through createRequire, which the orcad bundle
cannot follow, and nothing staged the package beside it. Bundle the SDK
into node_modules/@linear/sdk/index.js at build time and list it as an
orcad artifact so templates and installs carry it.

Co-authored-by: thukabjj <31043997+thukabjj@users.noreply.github.com>
2026-10-15 23:15:18 -07:00

55 lines
1.8 KiB
JavaScript

import { mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterAll, beforeAll, expect, it } from 'vitest'
import { runProcessSync } from '@orca/process-host'
import {
ORCAD_ARTIFACTS,
ORCAD_LINEAR_SDK_ENTRY,
ORCAD_SERVER_ENTRY_FILENAME
} from '../../src/shared/orcad-artifacts.ts'
import { stageOrcadLinearSdk } from './orcad-linear-sdk-package.mjs'
const root = join(import.meta.dirname, '..', '..')
// Outside the repo, so Node cannot fall back to the checkout's node_modules.
const deployment = realpathSync(mkdtempSync(join(tmpdir(), 'orcad-linear-sdk-')))
beforeAll(async () => {
await stageOrcadLinearSdk(root, deployment)
}, 60_000)
afterAll(() => {
rmSync(deployment, { recursive: true, force: true })
})
it('ships the SDK as a deployment artifact', () => {
expect(ORCAD_ARTIFACTS.map((artifact) => artifact.filename)).toContain(ORCAD_LINEAR_SDK_ENTRY)
})
it("resolves linear-sdk.ts's lazy require from the deployed server under plain Node", () => {
const server = join(deployment, ORCAD_SERVER_ENTRY_FILENAME)
writeFileSync(
server,
`const load = require('node:module').createRequire(__filename);
const sdk = load('@linear/sdk');
console.log(JSON.stringify({
resolved: load.resolve('@linear/sdk'),
client: typeof sdk.LinearClient,
authError: typeof sdk.AuthenticationLinearError
}));`
)
const loaded = runProcessSync({
program: process.execPath,
args: [server],
cwd: deployment,
env: { ORCA_BACKGROUND_LAUNCH: '1' },
timeoutMs: 30_000
})
expect(loaded.code, loaded.stderr.slice(-2_000)).toBe(0)
expect(JSON.parse(loaded.stdout.trim())).toEqual({
resolved: join(deployment, ORCAD_LINEAR_SDK_ENTRY),
client: 'function',
authError: 'function'
})
}, 40_000)