Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .githooks/sync-versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ function createFixtureRepo(): string {
version: initialVersion,
private: true
})
writeJson(join(rootDir, 'cli-integration-test', 'package.json'), {
name: '@truenine/memory-sync-cli-integration-test',
version: initialVersion,
private: true
})
writeJson(join(rootDir, 'cli', 'npm', 'darwin-arm64', 'package.json'), {
name: '@truenine/memory-sync-cli-darwin-arm64',
version: initialVersion
Expand Down Expand Up @@ -106,6 +111,7 @@ describe('sync-versions hook', () => {
expect(result.versionSource).toBe('cli/npm/darwin-arm64/package.json')
expect(JSON.parse(readFileSync(join(rootDir, 'package.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(JSON.parse(readFileSync(join(rootDir, 'cli', 'package.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(JSON.parse(readFileSync(join(rootDir, 'cli-integration-test', 'package.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(JSON.parse(readFileSync(join(rootDir, 'sdk', 'package.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(JSON.parse(readFileSync(join(rootDir, 'libraries', 'logger', 'package.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(readFileSync(join(rootDir, 'Cargo.toml'), 'utf-8')).toContain(`version = "${nextVersion}"`)
Expand All @@ -114,6 +120,7 @@ describe('sync-versions hook', () => {
expect(stagedFiles).toEqual(new Set([
'Cargo.toml',
'cli-crate/Cargo.toml',
'cli-integration-test/package.json',
'cli/npm/darwin-arm64/package.json',
'cli/package.json',
'gui/src-tauri/tauri.conf.json',
Expand Down Expand Up @@ -142,6 +149,45 @@ describe('sync-versions hook', () => {
expect(result.versionSource).toBe('sdk/package.json')
expect(JSON.parse(readFileSync(join(rootDir, 'package.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(JSON.parse(readFileSync(join(rootDir, 'cli', 'package.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(JSON.parse(readFileSync(join(rootDir, 'cli-integration-test', 'package.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(JSON.parse(readFileSync(join(rootDir, 'sdk', 'package.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(JSON.parse(readFileSync(join(rootDir, 'libraries', 'logger', 'package.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(readFileSync(join(rootDir, 'Cargo.toml'), 'utf-8')).toContain(`version = "${nextVersion}"`)
expect(readFileSync(join(rootDir, 'cli-crate', 'Cargo.toml'), 'utf-8')).toContain(`version = "${nextVersion}"`)
expect(JSON.parse(readFileSync(join(rootDir, 'gui', 'src-tauri', 'tauri.conf.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(stagedFiles).toEqual(new Set([
'Cargo.toml',
'cli-crate/Cargo.toml',
'cli-integration-test/package.json',
'cli/npm/darwin-arm64/package.json',
'cli/package.json',
'gui/src-tauri/tauri.conf.json',
'libraries/logger/package.json',
'package.json',
'sdk/package.json'
]))
})

it('accepts cli-integration-test/package.json as a staged version source and propagates it', () => {
const rootDir = createFixtureRepo()
tempDirs.push(rootDir)

const nextVersion = '2026.10324.10318'
writeJson(join(rootDir, 'cli-integration-test', 'package.json'), {
name: '@truenine/memory-sync-cli-integration-test',
version: nextVersion,
private: true
})
runGit(rootDir, ['add', 'cli-integration-test/package.json'])

const result = runSyncVersions({rootDir})
const stagedFiles = new Set(runGit(rootDir, ['diff', '--cached', '--name-only']).split(/\r?\n/).filter(Boolean))

expect(result.targetVersion).toBe(nextVersion)
expect(result.versionSource).toBe('cli-integration-test/package.json')
expect(JSON.parse(readFileSync(join(rootDir, 'package.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(JSON.parse(readFileSync(join(rootDir, 'cli', 'package.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(JSON.parse(readFileSync(join(rootDir, 'cli-integration-test', 'package.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(JSON.parse(readFileSync(join(rootDir, 'sdk', 'package.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(JSON.parse(readFileSync(join(rootDir, 'libraries', 'logger', 'package.json'), 'utf-8')) as {version: string}).toMatchObject({version: nextVersion})
expect(readFileSync(join(rootDir, 'Cargo.toml'), 'utf-8')).toContain(`version = "${nextVersion}"`)
Expand All @@ -150,6 +196,7 @@ describe('sync-versions hook', () => {
expect(stagedFiles).toEqual(new Set([
'Cargo.toml',
'cli-crate/Cargo.toml',
'cli-integration-test/package.json',
'cli/npm/darwin-arm64/package.json',
'cli/package.json',
'gui/src-tauri/tauri.conf.json',
Expand Down
1 change: 1 addition & 0 deletions .github/actions/setup-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ runs:
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ inputs.rust-version }}
components: rustfmt
targets: ${{ inputs.targets }}

- name: Cache cargo
Expand Down
1 change: 1 addition & 0 deletions .github/actions/setup-tauri/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ runs:
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ inputs.rust-version }}
components: rustfmt
targets: ${{ inputs.rust-targets }}

- name: Normalize Tauri signing key
Expand Down
23 changes: 21 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,27 @@ jobs:
- name: Build
run: pnpm run build

- name: Run all tests
run: pnpm run test
- name: Run workspace tests except container-backed CLI integration
run: pnpm exec turbo run test --ui=stream --log-order=grouped --filter='!@truenine/memory-sync-cli-integration-test'

test-cli-integration:
if: github.event.pull_request.draft == false
runs-on: ubuntu-24.04
timeout-minutes: 45
steps:
- uses: actions/checkout@v6

- uses: ./.github/actions/setup-node-pnpm

- uses: ./.github/actions/setup-rust
with:
cache-key: pr

- name: Verify Docker is available
run: docker version

- name: Run CLI integration tests
run: pnpm -C cli-integration-test run test

test-gui:
if: github.event.pull_request.draft == false
Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ members = [
]

[workspace.package]
version = "2026.10411.10132"
version = "2026.10412.11551"
edition = "2024"
rust-version = "1.88"
license = "AGPL-3.0-only"
Expand Down
20 changes: 20 additions & 0 deletions cli-integration-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@truenine/memory-sync-cli-integration-test",
"private": true,
"type": "module",
"version": "2026.10412.11551",
"description": "Container-backed CLI integration tests for tnmsc",
"scripts": {
"test": "vitest run",
"test:codex": "vitest run test/codex.integration.test.ts",
"test:claude-code": "vitest run test/claude-code-cli.integration.test.ts",
"test:integration": "pnpm run test",
"check:type": "tsc --noEmit -p tsconfig.test.json"
},
"devDependencies": {
"@types/node": "catalog:",
"testcontainers": "catalog:",
"typescript": "catalog:",
"vitest": "catalog:"
}
}
158 changes: 158 additions & 0 deletions cli-integration-test/src/artifacts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import {spawnSync} from 'node:child_process'
import {existsSync, mkdirSync, mkdtempSync, readdirSync, rmSync} from 'node:fs'
import {tmpdir} from 'node:os'
import path from 'node:path'
import {fileURLToPath} from 'node:url'

const REPO_ROOT = fileURLToPath(new URL('../../', import.meta.url))
const CLI_DIR = path.join(REPO_ROOT, 'cli')
const SCRIPT_RUNTIME_DIR = path.join(REPO_ROOT, 'libraries', 'script-runtime')
const CLI_LINUX_PACKAGE_DIR = path.join(CLI_DIR, 'npm', 'linux-x64-gnu')
const EXPECTED_LINUX_NODE_FILES = 4
const MAX_BUFFER = 16 * 1024 * 1024

export interface CliIntegrationArtifacts {
readonly tempDir: string
readonly cliTarballPath: string
readonly linuxTarballPath: string
readonly scriptRuntimeTarballPath: string
readonly latestPnpmVersion: string
}

let cachedArtifacts: CliIntegrationArtifacts | undefined
let cleanupRegistered = false

function registerArtifactCleanup(): void {
if (cleanupRegistered) return

cleanupRegistered = true
process.once('exit', () => {
cleanupCliIntegrationArtifacts()
})
}

function runCommand(
command: string,
args: readonly string[],
cwd: string = REPO_ROOT
): string {
const result = spawnSync(command, args, {
cwd,
encoding: 'utf8',
maxBuffer: MAX_BUFFER
})

if (result.error != null) throw result.error
if (result.status === 0) return `${result.stdout ?? ''}${result.stderr ?? ''}`

throw new Error([
`Command failed: ${command} ${args.join(' ')}`,
`cwd: ${cwd}`,
`${result.stdout ?? ''}${result.stderr ?? ''}`.trim() || 'No output captured.'
].join('\n'))
}

function resolveLatestPackageVersion(packageName: string): string {
const raw = runCommand(
'npm',
['view', packageName, 'version'],
tmpdir()
).trim()
const firstLine = raw
.split(/\r?\n/u)
.map(line => line.trim())
.find(line => line.length > 0)

if (firstLine != null) return firstLine

throw new Error(`Failed to resolve the latest version for "${packageName}".`)
}

function ensureDirectory(dirPath: string): void {
mkdirSync(dirPath, {recursive: true})
}

function findSingleTarball(dirPath: string): string {
const tarballs = readdirSync(dirPath)
.filter(fileName => fileName.endsWith('.tgz'))
.sort()

if (tarballs.length !== 1) {
throw new Error(
`Expected exactly one tarball in "${dirPath}", found ${tarballs.length}.`
)
}

return path.join(dirPath, tarballs[0] ?? '')
}

function packWorkspacePackage(packageDir: string, targetDir: string): string {
ensureDirectory(targetDir)
runCommand('pnpm', ['-C', packageDir, 'pack', '--pack-destination', targetDir])
return findSingleTarball(targetDir)
}

function ensureLinuxPlatformPackageReady(): void {
const nodeFiles = existsSync(CLI_LINUX_PACKAGE_DIR)
? readdirSync(CLI_LINUX_PACKAGE_DIR).filter(fileName => fileName.endsWith('.node'))
: []

if (nodeFiles.length >= EXPECTED_LINUX_NODE_FILES) return

runCommand('pnpm', ['-C', CLI_DIR, 'run', 'build:napi:copy'])

const copiedNodeFiles = readdirSync(CLI_LINUX_PACKAGE_DIR)
.filter(fileName => fileName.endsWith('.node'))

if (copiedNodeFiles.length < EXPECTED_LINUX_NODE_FILES) {
throw new Error(
`Expected ${EXPECTED_LINUX_NODE_FILES} Linux x64 NAPI artifacts in "${CLI_LINUX_PACKAGE_DIR}", found ${copiedNodeFiles.length}.`
)
}
}

function assertSupportedHost(): void {
if (process.platform === 'linux' && process.arch === 'x64') return

throw new Error(
`cli-integration-test currently supports only linux-x64 hosts. Current host: ${process.platform}-${process.arch}.`
)
}

export function prepareCliIntegrationArtifacts(): CliIntegrationArtifacts {
if (cachedArtifacts != null) return cachedArtifacts

assertSupportedHost()
registerArtifactCleanup()
runCommand('pnpm', ['-C', CLI_DIR, 'run', 'build'])
ensureLinuxPlatformPackageReady()

const tempDir = mkdtempSync(path.join(tmpdir(), 'tnmsc-cli-integration-artifacts-'))
const cliTarballPath = packWorkspacePackage(CLI_DIR, path.join(tempDir, 'cli'))
const linuxTarballPath = packWorkspacePackage(
CLI_LINUX_PACKAGE_DIR,
path.join(tempDir, 'cli-linux-x64')
)
const scriptRuntimeTarballPath = packWorkspacePackage(
SCRIPT_RUNTIME_DIR,
path.join(tempDir, 'script-runtime')
)
const latestPnpmVersion = resolveLatestPackageVersion('pnpm')

cachedArtifacts = {
tempDir,
cliTarballPath,
linuxTarballPath,
scriptRuntimeTarballPath,
latestPnpmVersion
}

return cachedArtifacts
}

export function cleanupCliIntegrationArtifacts(): void {
if (cachedArtifacts == null) return

rmSync(cachedArtifacts.tempDir, {recursive: true, force: true})
cachedArtifacts = void 0
}
Loading
Loading