Skip to content

Commit cf8031a

Browse files
committed
Enhance SDK core functionality with integration test coverage and diagnostics
- Add cli-integration-test artifact and container modules - Add runtime test coverage in cli module - Add adaptor-core improvements for AbstractOutputAdaptor, GlobalScopeCollector, LocalizedPromptReader - Add PromptArtifactCache, PromptCompilerDiagnostics, and PromptTypes improvements - Update native bindings: prompt_artifact.rs, native_md_compiler transformer and serializer - Add diagnostic_helpers and update lib exports
1 parent 49704a9 commit cf8031a

21 files changed

Lines changed: 111 additions & 100 deletions

cli-integration-test/src/artifacts.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import {fileURLToPath} from 'node:url'
66

77
const REPO_ROOT = fileURLToPath(new URL('../../', import.meta.url))
88
const CLI_DIR = path.join(REPO_ROOT, 'cli')
9-
const SCRIPT_RUNTIME_DIR = path.join(REPO_ROOT, 'libraries', 'script-runtime')
9+
const SDK_DIR = path.join(REPO_ROOT, 'sdk')
1010
const CLI_LINUX_PACKAGE_DIR = path.join(CLI_DIR, 'npm', 'linux-x64-gnu')
11-
const EXPECTED_LINUX_NODE_FILES = 4
11+
const REQUIRED_LINUX_NODE_FILE = 'napi-memory-sync-cli.linux-x64-gnu.node'
1212
const MAX_BUFFER = 16 * 1024 * 1024
1313

1414
export interface CliIntegrationArtifacts {
1515
readonly tempDir: string
1616
readonly cliTarballPath: string
1717
readonly linuxTarballPath: string
18-
readonly scriptRuntimeTarballPath: string
18+
readonly sdkTarballPath: string
1919
readonly latestPnpmVersion: string
2020
}
2121

@@ -93,20 +93,20 @@ function packWorkspacePackage(packageDir: string, targetDir: string): string {
9393
}
9494

9595
function ensureLinuxPlatformPackageReady(): void {
96-
const nodeFiles = existsSync(CLI_LINUX_PACKAGE_DIR)
97-
? readdirSync(CLI_LINUX_PACKAGE_DIR).filter(fileName => fileName.endsWith('.node'))
98-
: []
96+
const hasRequiredNodeFile = existsSync(CLI_LINUX_PACKAGE_DIR)
97+
&& readdirSync(CLI_LINUX_PACKAGE_DIR).includes(REQUIRED_LINUX_NODE_FILE)
9998

100-
if (nodeFiles.length >= EXPECTED_LINUX_NODE_FILES) return
99+
if (hasRequiredNodeFile) return
101100

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

104-
const copiedNodeFiles = readdirSync(CLI_LINUX_PACKAGE_DIR)
105-
.filter(fileName => fileName.endsWith('.node'))
103+
const copiedNodeFiles = existsSync(CLI_LINUX_PACKAGE_DIR)
104+
? readdirSync(CLI_LINUX_PACKAGE_DIR).filter(fileName => fileName.endsWith('.node'))
105+
: []
106106

107-
if (copiedNodeFiles.length < EXPECTED_LINUX_NODE_FILES) {
107+
if (!copiedNodeFiles.includes(REQUIRED_LINUX_NODE_FILE)) {
108108
throw new Error(
109-
`Expected ${EXPECTED_LINUX_NODE_FILES} Linux x64 NAPI artifacts in "${CLI_LINUX_PACKAGE_DIR}", found ${copiedNodeFiles.length}.`
109+
`Expected the Linux x64 NAPI artifact "${REQUIRED_LINUX_NODE_FILE}" in "${CLI_LINUX_PACKAGE_DIR}", found ${copiedNodeFiles.length} .node file(s): ${copiedNodeFiles.join(', ') || '(none)'}.`
110110
)
111111
}
112112
}
@@ -133,17 +133,17 @@ export function prepareCliIntegrationArtifacts(): CliIntegrationArtifacts {
133133
CLI_LINUX_PACKAGE_DIR,
134134
path.join(tempDir, 'cli-linux-x64')
135135
)
136-
const scriptRuntimeTarballPath = packWorkspacePackage(
137-
SCRIPT_RUNTIME_DIR,
138-
path.join(tempDir, 'script-runtime')
136+
const sdkTarballPath = packWorkspacePackage(
137+
SDK_DIR,
138+
path.join(tempDir, 'sdk')
139139
)
140140
const latestPnpmVersion = resolveLatestPackageVersion('pnpm')
141141

142142
cachedArtifacts = {
143143
tempDir,
144144
cliTarballPath,
145145
linuxTarballPath,
146-
scriptRuntimeTarballPath,
146+
sdkTarballPath,
147147
latestPnpmVersion
148148
}
149149

cli-integration-test/src/container.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,22 +243,22 @@ export class PreparedCliIntegrationContainer {
243243
this.copyPathToContainer(artifacts.cliTarballPath, containerTarballPath(artifacts.cliTarballPath))
244244
this.copyPathToContainer(artifacts.linuxTarballPath, containerTarballPath(artifacts.linuxTarballPath))
245245
this.copyPathToContainer(
246-
artifacts.scriptRuntimeTarballPath,
247-
containerTarballPath(artifacts.scriptRuntimeTarballPath)
246+
artifacts.sdkTarballPath,
247+
containerTarballPath(artifacts.sdkTarballPath)
248248
)
249249
}
250250

251251
bootstrapLatestPnpmAndInstallCli(artifacts: CliIntegrationArtifacts): void {
252252
const cliTarball = containerTarballPath(artifacts.cliTarballPath)
253253
const linuxTarball = containerTarballPath(artifacts.linuxTarballPath)
254-
const scriptRuntimeTarball = containerTarballPath(artifacts.scriptRuntimeTarballPath)
254+
const sdkTarball = containerTarballPath(artifacts.sdkTarballPath)
255255

256256
this.assertExecSuccess(
257257
[
258258
'corepack enable',
259259
`corepack prepare pnpm@${quoteShell(artifacts.latestPnpmVersion)} --activate`,
260260
'pnpm --version',
261-
`pnpm add -g ${quoteShell(cliTarball)} ${quoteShell(linuxTarball)} ${quoteShell(scriptRuntimeTarball)}`,
261+
`pnpm add -g ${quoteShell(cliTarball)} ${quoteShell(linuxTarball)} ${quoteShell(sdkTarball)}`,
262262
buildPinnedGlobalCliPlatformLinkScript(),
263263
'command -v tnmsc >/dev/null'
264264
].join(' && ')

cli/src/cli-runtime.test.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
import {afterEach, describe, expect, it, vi} from 'vitest'
22

3-
const {cleanMock, dryRunMock, installMock, listAdaptorsMock} = vi.hoisted(() => ({
3+
const {
4+
cleanMock,
5+
dryRunMock,
6+
flushOutputMock,
7+
installMock,
8+
listAdaptorsMock,
9+
setGlobalLogLevelMock
10+
} = vi.hoisted(() => ({
411
cleanMock: vi.fn(),
512
dryRunMock: vi.fn(),
13+
flushOutputMock: vi.fn(),
614
installMock: vi.fn(),
7-
listAdaptorsMock: vi.fn()
15+
listAdaptorsMock: vi.fn(),
16+
setGlobalLogLevelMock: vi.fn()
817
}))
918

1019
vi.mock('@truenine/memory-sync-sdk', () => ({
20+
flushOutput: flushOutputMock,
1121
getMemorySyncSdkBinding() {
1222
return {
1323
install: installMock,
1424
dryRun: dryRunMock,
1525
clean: cleanMock,
1626
listAdaptors: listAdaptorsMock
1727
}
18-
}
28+
},
29+
setGlobalLogLevel: setGlobalLogLevelMock
1930
}))
2031

2132
afterEach(() => {

sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
},
6868
"devDependencies": {
6969
"@clack/prompts": "catalog:",
70-
"@types/fs-extra": "catalog:",
7170
"@types/estree": "catalog:",
7271
"@types/estree-jsx": "catalog:",
72+
"@types/fs-extra": "catalog:",
7373
"@types/mdast": "catalog:",
7474
"@types/picomatch": "catalog:",
7575
"@vitest/coverage-v8": "catalog:",

sdk/src/adaptors/adaptor-core/AbstractOutputAdaptor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type {BuildPromptTomlArtifactOptions} from '@/md-compiler'
21
import type {ToolPresetName} from './GlobalScopeCollector'
32
import type {RegistryWriter} from './RegistryWriter'
43
import type {
@@ -32,13 +31,14 @@ import type {
3231
SubAgentYAMLFrontMatter,
3332
WslMirrorFileDeclaration
3433
} from './types'
34+
import type {BuildPromptTomlArtifactOptions} from '@/md-compiler'
3535
import {Buffer} from 'node:buffer'
3636
import * as path from 'node:path'
3737
import process from 'node:process'
3838

39+
import {buildConfigDiagnostic, diagnosticLines} from '@/diagnostics'
3940
import {buildPromptTomlArtifact} from '@/md-compiler'
4041
import {buildMarkdownWithFrontMatter, buildMarkdownWithRawFrontMatter} from '@/md-compiler/markdown'
41-
import {buildConfigDiagnostic, diagnosticLines} from '@/diagnostics'
4242
import {getEffectiveHomeDir} from '@/runtime-environment'
4343
import {AbstractAdaptor} from './AbstractAdaptor'
4444
import {AdaptorKind, FilePathKind} from './enums'

sdk/src/adaptors/adaptor-core/GlobalScopeCollector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type {AdaptorOptions, UserConfigFile} from './types'
12
import type {EvaluationScope} from '@/md-compiler'
23
import type {CodeStylePreferences, EnvironmentContext, MdComponent, MdxGlobalScope, OsInfo, ToolReferences, UserProfile} from '@/md-compiler/globals' // Collects and manages global scope variables for MDX expression evaluation.
3-
import type {AdaptorOptions, UserConfigFile} from './types'
44
import * as os from 'node:os'
55
import process from 'node:process'
66
import {OsKind, ShellKind, ToolPresets} from '@/md-compiler/globals'

sdk/src/adaptors/adaptor-core/LocalizedPromptReader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type {MdxGlobalScope} from '@/md-compiler/globals'
21
import type {PromptCompilerDiagnosticContext} from './PromptCompilerDiagnostics'
32
import type {
43
DirectoryReadResult,
@@ -13,6 +12,7 @@ import type {
1312
PromptKind,
1413
ReadError
1514
} from './types'
15+
import type {MdxGlobalScope} from '@/md-compiler/globals'
1616
import {
1717
buildDiagnostic,
1818
buildFileOperationDiagnostic,

sdk/src/adaptors/adaptor-core/PromptArtifactCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type {MdxGlobalScope} from '@/md-compiler/globals'
22
import type {ParsedMarkdown} from '@/md-compiler/markdown'
33
import * as fs from 'node:fs'
44
import * as path from 'node:path'
5+
import JSON5 from 'json5'
56
import {mdxToMd} from '@/md-compiler'
67
import {parseMarkdown} from '@/md-compiler/markdown'
7-
import JSON5 from 'json5'
88

99
export interface PromptArtifact {
1010
readonly rawMdx: string

sdk/src/adaptors/adaptor-core/PromptCompilerDiagnostics.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'node:path'
2-
import {UndefinedNamespaceError} from '@/md-compiler/errors'
32
import {describe, expect, it} from 'vitest'
3+
import {UndefinedNamespaceError} from '@/md-compiler/errors'
44
import {
55
formatPromptCompilerDiagnostic,
66
resolveSourcePathForDistFile

sdk/src/adaptors/adaptor-core/PromptTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type {Root, RootContent} from '@/md-compiler'
21
import type {ClaudeCodeCLISubAgentColors, CodingAgentTools, FilePathKind, NamingCaseKind, PromptKind, RuleScope} from './enums'
32
import type {GlobalConfigDirectory} from './OutputTypes'
3+
import type {Root, RootContent} from '@/md-compiler'
44

55
/** Common directory representation */
66
export interface Path<K extends FilePathKind = FilePathKind> {

0 commit comments

Comments
 (0)