@buaa_smat/hometrans 0.1.19 → 0.1.20
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/README.md +18 -0
- package/agents/code-reviewer.md +1 -1
- package/agents/self-tester.md +33 -354
- package/agents/test-case-generation-generator.md +1 -1
- package/dist/cli/config-store.js +4 -84
- package/dist/cli/config.js +6 -8
- package/dist/cli/init.js +29 -36
- package/dist/cli/uninstall.js +2 -2
- package/env-requirements.json +5 -4
- package/package.json +3 -5
- package/resource/project_architecture.svg +1 -1
- package/skills/hmos-convert-pipeline/SKILL.md +31 -21
- package/skills/hmos-incremental-ui-align/README.md +5 -5
- package/skills/hmos-incremental-ui-align/SKILL.md +2 -2
- package/skills/hmos-integration-test/README.md +58 -17
- package/skills/hmos-integration-test/SKILL.md +107 -40
- package/{tools/test-tools/autotest/engine → skills/hmos-integration-test/scripts}/report-tool.ts +71 -53
- package/skills/hmos-integration-test/scripts/resolve-metadata-tool.ts +125 -0
- package/skills/hmos-integration-test/scripts/self-test-runner.ts +756 -0
- package/{tools/test-tools/autotest/engine → skills/hmos-integration-test/scripts}/testcases-tool.ts +38 -45
- package/skills/hmos-test-case-generation/references/contract.md +3 -3
- package/tools/test-tools/autotest/config.ts +0 -175
- package/tools/test-tools/autotest/deps/autotest-agent-0.1.1.tgz +0 -0
- package/tools/test-tools/autotest/docs/README.md +0 -266
- package/tools/test-tools/autotest/docs/testcases_schema.md +0 -143
- package/tools/test-tools/autotest/engine/batch-launcher.ts +0 -327
- package/tools/test-tools/autotest/engine/self-test-runner.ts +0 -961
- package/tools/test-tools/autotest/paths.ts +0 -41
- package/tools/test-tools/autotest/resolve-metadata-tool.ts +0 -143
- package/tools/test-tools/autotest/runner/logger.ts +0 -45
- package/tools/test-tools/autotest/runner/process-utils.ts +0 -41
- package/tools/test-tools/autotest/validate.ts +0 -167
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared path resolution for the AutoTest CLI tools
|
|
3
|
-
* (testcases-tool / report-tool / self-test-runner TS ports).
|
|
4
|
-
*
|
|
5
|
-
* Replaces Python's `SCRIPT_DIR = Path(__file__).resolve().parent` and the
|
|
6
|
-
* `~/.hometrans/config.json` + `HOMETRANS_TOOL_PATH` autotest-dir resolution
|
|
7
|
-
* chain that lived at the top of `self_test_runner.py`.
|
|
8
|
-
*/
|
|
9
|
-
import fs from 'node:fs';
|
|
10
|
-
import os from 'node:os';
|
|
11
|
-
import path from 'node:path';
|
|
12
|
-
import { fileURLToPath } from 'node:url';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Directory of the running JS file. Mirrors Python's `Path(__file__).parent`.
|
|
16
|
-
* Resolves to the autotest source dir `tools/test-tools/autotest/` at runtime.
|
|
17
|
-
*
|
|
18
|
-
* Resolution order: source-tree walk-up → `HOMETRANS_TOOL_PATH` →
|
|
19
|
-
* `~/.hometrans/tools`. `HOMETRANS_TOOL_PATH` is the single tools-dir env var;
|
|
20
|
-
* there is deliberately no autotest-specific override.
|
|
21
|
-
*/
|
|
22
|
-
export function autotestDir(): string {
|
|
23
|
-
// Prefer the source-tree / npm package directory — always current after
|
|
24
|
-
// `npm update`, no need for the user to re-run `ht init` to sync.
|
|
25
|
-
// Walk up from this module's location until we find `tools/test-tools/autotest`.
|
|
26
|
-
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
27
|
-
let dir = here;
|
|
28
|
-
for (let i = 0; i < 10 && dir; i++) {
|
|
29
|
-
const probe = path.join(dir, 'tools', 'test-tools', 'autotest');
|
|
30
|
-
if (fs.existsSync(probe)) return probe;
|
|
31
|
-
const parent = path.dirname(dir);
|
|
32
|
-
if (parent === dir) break;
|
|
33
|
-
dir = parent;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Fallback: `HOMETRANS_TOOL_PATH` (persisted by `ht init`) → ~/.hometrans/tools.
|
|
37
|
-
const toolPath =
|
|
38
|
-
process.env.HOMETRANS_TOOL_PATH || path.join(os.homedir(), '.hometrans', 'tools');
|
|
39
|
-
const candidate = path.join(toolPath, 'test-tools', 'autotest');
|
|
40
|
-
return candidate; // return the canonical path even if absent; caller will error clearly
|
|
41
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolve App Metadata — discover `bundle_name` / `app_name` from a HarmonyOS
|
|
3
|
-
* project and write `app-metadata.json`.
|
|
4
|
-
*
|
|
5
|
-
* Subcommand:
|
|
6
|
-
* resolve-metadata --project-dir <dir> --output <path>
|
|
7
|
-
* Reads `<project-dir>/AppScope/app.json5` (JSON5 via jsonc-parser),
|
|
8
|
-
* extracts `app.bundleName` and `app.label` (resolving `$string:xxx`
|
|
9
|
-
* references from the base-qualifier string.json), writes
|
|
10
|
-
* `{bundle_name, app_name, project_root}` to `--output`, and emits the
|
|
11
|
-
* same JSON to stdout.
|
|
12
|
-
*
|
|
13
|
-
* Exit codes: 0 = success (JSON emitted + file written), 1 = any failure
|
|
14
|
-
* (invalid project root, JSON5 parse failure, missing bundleName, write
|
|
15
|
-
* failure). Errors go to stderr; stdout carries exactly one JSON line on
|
|
16
|
-
* success. This is the deterministic replacement for the LLM-driven discovery
|
|
17
|
-
* that previously lived in the self-tester agent prompt (S2/S3).
|
|
18
|
-
*/
|
|
19
|
-
import fs from 'node:fs';
|
|
20
|
-
import path from 'node:path';
|
|
21
|
-
import { fileURLToPath } from 'node:url';
|
|
22
|
-
import { Command } from 'commander';
|
|
23
|
-
import { parse as parseJsonc, printParseErrorCode, type ParseError } from 'jsonc-parser';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Resolve a `$string:<key>` reference from `AppScope/resources/base/element/string.json`
|
|
27
|
-
* (the HarmonyOS base-qualifier string resource file). Returns the value, or null
|
|
28
|
-
* when the file is missing / unparseable / the key is absent. The caller falls back
|
|
29
|
-
* to the literal `$string:xxx` text on null — app_name is a display name, not
|
|
30
|
-
* load-bearing, so a missing resource must not fail the run.
|
|
31
|
-
*/
|
|
32
|
-
function resolveStringResource(projectRoot: string, key: string): string | null {
|
|
33
|
-
const stringJson = path.join(
|
|
34
|
-
projectRoot, 'AppScope', 'resources', 'base', 'element', 'string.json',
|
|
35
|
-
);
|
|
36
|
-
if (!fs.existsSync(stringJson)) return null;
|
|
37
|
-
let doc: unknown;
|
|
38
|
-
try {
|
|
39
|
-
doc = parseJsonc(fs.readFileSync(stringJson, 'utf-8'));
|
|
40
|
-
} catch {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
const arr = (doc as { string?: unknown })?.string;
|
|
44
|
-
if (!Array.isArray(arr)) return null;
|
|
45
|
-
const entry = arr.find((e) => (e as { name?: unknown })?.name === key);
|
|
46
|
-
const value = (entry as { value?: unknown } | undefined)?.value;
|
|
47
|
-
return typeof value === 'string' && value ? value : null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface ResolveMetadataArgs {
|
|
51
|
-
projectDir: string;
|
|
52
|
-
output: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function cmdResolveMetadata(args: ResolveMetadataArgs): void {
|
|
56
|
-
const projectRoot = path.resolve(args.projectDir);
|
|
57
|
-
|
|
58
|
-
const appJson5 = path.join(projectRoot, 'AppScope', 'app.json5');
|
|
59
|
-
if (!fs.existsSync(appJson5)) {
|
|
60
|
-
console.error(`not a HarmonyOS project root (no AppScope/app.json5): ${projectRoot}`);
|
|
61
|
-
process.exit(1);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
let doc: unknown;
|
|
65
|
-
const errs: ParseError[] = [];
|
|
66
|
-
try {
|
|
67
|
-
doc = parseJsonc(fs.readFileSync(appJson5, 'utf-8'), errs, { allowTrailingComma: true });
|
|
68
|
-
} catch (e) {
|
|
69
|
-
console.error(`failed to parse ${appJson5}: ${e instanceof Error ? e.message : String(e)}`);
|
|
70
|
-
process.exit(1);
|
|
71
|
-
}
|
|
72
|
-
if (errs.length > 0) {
|
|
73
|
-
console.error(
|
|
74
|
-
`failed to parse ${appJson5}: ${errs.map((e) => printParseErrorCode(e.error)).join('; ')}`,
|
|
75
|
-
);
|
|
76
|
-
process.exit(1);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const app = (doc as { app?: Record<string, unknown> })?.app;
|
|
80
|
-
const bundleName = app?.bundleName;
|
|
81
|
-
if (typeof bundleName !== 'string' || !bundleName) {
|
|
82
|
-
console.error(`missing app.bundleName (string) in ${appJson5}`);
|
|
83
|
-
process.exit(1);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const label = app?.label;
|
|
87
|
-
let appName: string;
|
|
88
|
-
if (typeof label === 'string' && label.startsWith('$string:')) {
|
|
89
|
-
const key = label.slice('$string:'.length);
|
|
90
|
-
const resolved = resolveStringResource(projectRoot, key);
|
|
91
|
-
if (resolved) {
|
|
92
|
-
appName = resolved;
|
|
93
|
-
} else {
|
|
94
|
-
console.error(
|
|
95
|
-
`warning: string resource '${key}' not found in AppScope/resources/base/element/string.json — ` +
|
|
96
|
-
`using literal '${label}' as app_name`,
|
|
97
|
-
);
|
|
98
|
-
appName = label;
|
|
99
|
-
}
|
|
100
|
-
} else if (typeof label === 'string' && label) {
|
|
101
|
-
appName = label;
|
|
102
|
-
} else {
|
|
103
|
-
// ponytail: label missing/empty — bundleName is a valid non-empty string, reuse it.
|
|
104
|
-
// app_name is display-only; failing the whole run over it would be over-strict.
|
|
105
|
-
console.error(`warning: missing app.label in ${appJson5} — using bundleName as app_name`);
|
|
106
|
-
appName = bundleName;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const meta = { bundle_name: bundleName, app_name: appName, project_root: projectRoot };
|
|
110
|
-
|
|
111
|
-
try {
|
|
112
|
-
fs.mkdirSync(path.dirname(path.resolve(args.output)), { recursive: true });
|
|
113
|
-
fs.writeFileSync(path.resolve(args.output), JSON.stringify(meta) + '\n', 'utf-8');
|
|
114
|
-
} catch (e) {
|
|
115
|
-
console.error(`failed to write ${args.output}: ${e instanceof Error ? e.message : String(e)}`);
|
|
116
|
-
process.exit(1);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
console.log(JSON.stringify(meta));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/** CLI entry — wires up the `resolve-metadata` subcommand. */
|
|
123
|
-
export function main(): void {
|
|
124
|
-
const program = new Command();
|
|
125
|
-
program
|
|
126
|
-
.description('从 HarmonyOS 工程解析 bundle_name/app_name 并写 app-metadata.json')
|
|
127
|
-
.requiredOption('--project-dir <dir>', 'HarmonyOS 工程根目录(含 AppScope/app.json5)')
|
|
128
|
-
.requiredOption('--output <path>', 'app-metadata.json 输出路径')
|
|
129
|
-
.action((opts: ResolveMetadataArgs) => {
|
|
130
|
-
cmdResolveMetadata({ projectDir: opts.projectDir, output: opts.output });
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
program.parseAsync(process.argv).catch((err) => {
|
|
134
|
-
console.error(err instanceof Error ? err.message : err);
|
|
135
|
-
process.exit(1);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
140
|
-
const isMainEntry = !!process.argv[1] && fs.realpathSync(process.argv[1]) === __filename;
|
|
141
|
-
if (isMainEntry) {
|
|
142
|
-
main();
|
|
143
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Minimal logger for the self-test runner. Writes `[timestamp] LEVEL msg` to an
|
|
3
|
-
* optional file stream and to stderr — never stdout, which carries the strict
|
|
4
|
-
* JSON the orchestrator parses.
|
|
5
|
-
*/
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
|
|
8
|
-
/** Format a Date as `YYYY-MM-DD HH:MM:SS`. Shared with self-test-runner's status log. */
|
|
9
|
-
export function formatLogTimestamp(d: Date): string {
|
|
10
|
-
const pad = (n: number) => String(n).padStart(2, '0');
|
|
11
|
-
return (
|
|
12
|
-
`${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ` +
|
|
13
|
-
`${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface Logger {
|
|
18
|
-
info(msg: string): void;
|
|
19
|
-
warning(msg: string): void;
|
|
20
|
-
error(msg: string): void;
|
|
21
|
-
debug(msg: string): void;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type Level = 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR';
|
|
25
|
-
const LEVEL_RANK: Record<Level, number> = { DEBUG: 0, INFO: 1, WARNING: 2, ERROR: 3 };
|
|
26
|
-
|
|
27
|
-
/** Logger writing to `stream` (if non-null) and stderr; drops messages below `minLevel`. */
|
|
28
|
-
export function createLogger(
|
|
29
|
-
stream: fs.WriteStream | null,
|
|
30
|
-
minLevel: 'DEBUG' | 'INFO' = 'DEBUG',
|
|
31
|
-
): Logger {
|
|
32
|
-
const rank = LEVEL_RANK[minLevel];
|
|
33
|
-
const write = (level: Level, msg: string): void => {
|
|
34
|
-
if (LEVEL_RANK[level] < rank) return;
|
|
35
|
-
const line = `[${formatLogTimestamp(new Date())}] ${level} ${msg}`;
|
|
36
|
-
if (stream) stream.write(line + '\n');
|
|
37
|
-
process.stderr.write(line + '\n');
|
|
38
|
-
};
|
|
39
|
-
return {
|
|
40
|
-
info: (m) => write('INFO', m),
|
|
41
|
-
warning: (m) => write('WARNING', m),
|
|
42
|
-
error: (m) => write('ERROR', m),
|
|
43
|
-
debug: (m) => write('DEBUG', m),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Process helpers for the self-test runner: native liveness + tree-kill.
|
|
3
|
-
*/
|
|
4
|
-
import { execFileSync } from 'node:child_process';
|
|
5
|
-
|
|
6
|
-
const IS_WIN = process.platform === 'win32';
|
|
7
|
-
|
|
8
|
-
/** Whether `pid` is alive, via `kill(pid, 0)`: ESRCH = dead, EPERM = alive. */
|
|
9
|
-
export function pidAlive(pid: number): boolean {
|
|
10
|
-
try {
|
|
11
|
-
process.kill(pid, 0);
|
|
12
|
-
return true;
|
|
13
|
-
} catch (e) {
|
|
14
|
-
return (e as NodeJS.ErrnoException).code === 'EPERM';
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** Kill `pid` + descendants. Windows: `taskkill /F /T`; POSIX: SIGKILL the group then the pid. Best-effort. */
|
|
19
|
-
export function killProcessTree(pid: number): void {
|
|
20
|
-
if (IS_WIN) {
|
|
21
|
-
try {
|
|
22
|
-
execFileSync('taskkill', ['/F', '/T', '/PID', String(pid)], {
|
|
23
|
-
timeout: 10000,
|
|
24
|
-
windowsHide: true,
|
|
25
|
-
stdio: 'ignore',
|
|
26
|
-
});
|
|
27
|
-
} catch {
|
|
28
|
-
// best effort
|
|
29
|
-
}
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
process.kill(-pid, 'SIGKILL');
|
|
34
|
-
} catch {
|
|
35
|
-
try {
|
|
36
|
-
process.kill(pid, 'SIGKILL');
|
|
37
|
-
} catch {
|
|
38
|
-
// best effort
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Self-test input validation gates — TS ports of the `uv run python -c "..."`
|
|
3
|
-
* one-liners that previously lived inline in `agents/self-tester.md`.
|
|
4
|
-
*
|
|
5
|
-
* Folding them here removes a cold Python+uv start per check (5 per run) and
|
|
6
|
-
* gives the logic a single, typed, testable home. Each function is pure and
|
|
7
|
-
* returns `{ ok, message }`; the CLI layer prints `message` to stdout on
|
|
8
|
-
* success or stderr+exit(1) on failure, matching the prompt's `… && echo OK`
|
|
9
|
-
* expectation. No stdout-JSON contract applies to these gates (unlike
|
|
10
|
-
* run/status/kill) — they are simple human-readable pass/fail checks.
|
|
11
|
-
*/
|
|
12
|
-
import fs from 'node:fs';
|
|
13
|
-
import path from 'node:path';
|
|
14
|
-
import { autotestDir } from './paths.ts';
|
|
15
|
-
import { loadAutotestConfig, AutotestConfigError } from './config.ts';
|
|
16
|
-
|
|
17
|
-
export interface CheckResult {
|
|
18
|
-
ok: boolean;
|
|
19
|
-
message: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* `hap_path` is a comma-separated list of files/dirs — each entry a
|
|
24
|
-
* `.hap`/`.hsp` file or a directory. Every entry must exist and, across all
|
|
25
|
-
* entries, at least one `.hap` (the entry package) must be present.
|
|
26
|
-
* (Replaces self-tester.md T1's hap validation one-liner.)
|
|
27
|
-
*/
|
|
28
|
-
export function checkHap(hapArg: string): CheckResult {
|
|
29
|
-
const parts = hapArg
|
|
30
|
-
.split(',')
|
|
31
|
-
.map((s) => s.trim())
|
|
32
|
-
.filter(Boolean);
|
|
33
|
-
if (parts.length === 0) return { ok: false, message: 'hap_path empty' };
|
|
34
|
-
|
|
35
|
-
for (const p of parts) {
|
|
36
|
-
if (!fs.existsSync(p)) return { ok: false, message: `path not found: ${p}` };
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const haps: string[] = [];
|
|
40
|
-
for (const p of parts) {
|
|
41
|
-
const names = fs.statSync(p).isDirectory() ? fs.readdirSync(p) : [path.basename(p)];
|
|
42
|
-
for (const n of names) {
|
|
43
|
-
if (n.toLowerCase().endsWith('.hap')) haps.push(n);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (haps.length === 0) {
|
|
47
|
-
return { ok: false, message: 'no entry .hap found across hap_path entries' };
|
|
48
|
-
}
|
|
49
|
-
return { ok: true, message: 'OK' };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* `setup=false` precondition: both JSONs must parse, `testcases.json` must be a
|
|
54
|
-
* non-empty array, and `app-metadata.json` must carry the required keys.
|
|
55
|
-
* (Replaces self-tester.md T1's setup=false JSON check one-liner.)
|
|
56
|
-
*/
|
|
57
|
-
export function checkInputs(testcasesPath: string, metadataPath: string): CheckResult {
|
|
58
|
-
let t: unknown;
|
|
59
|
-
try {
|
|
60
|
-
t = JSON.parse(fs.readFileSync(testcasesPath, 'utf-8'));
|
|
61
|
-
} catch (e) {
|
|
62
|
-
return { ok: false, message: `testcases.json failed to parse: ${(e as Error).message}` };
|
|
63
|
-
}
|
|
64
|
-
if (!Array.isArray(t) || t.length === 0) {
|
|
65
|
-
return { ok: false, message: 'testcases.json empty or not a list' };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
let m: unknown;
|
|
69
|
-
try {
|
|
70
|
-
m = JSON.parse(fs.readFileSync(metadataPath, 'utf-8'));
|
|
71
|
-
} catch (e) {
|
|
72
|
-
return { ok: false, message: `app-metadata.json failed to parse: ${(e as Error).message}` };
|
|
73
|
-
}
|
|
74
|
-
// A JSON primitive/array has no keys → treat as missing fields (avoids the
|
|
75
|
-
// `in` operator throwing a TypeError on a non-object).
|
|
76
|
-
if (typeof m !== 'object' || m === null || Array.isArray(m)) {
|
|
77
|
-
return { ok: false, message: 'app-metadata.json missing required fields' };
|
|
78
|
-
}
|
|
79
|
-
const mo = m as Record<string, unknown>;
|
|
80
|
-
for (const k of ['bundle_name', 'app_name', 'project_root']) {
|
|
81
|
-
if (!(k in mo)) return { ok: false, message: 'app-metadata.json missing required fields' };
|
|
82
|
-
}
|
|
83
|
-
return { ok: true, message: 'OK' };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* `[PRE]` cases must occupy a contiguous block starting at index 0 in
|
|
88
|
-
* `testcases.json`. Run only when pre-cases were extracted.
|
|
89
|
-
* (Replaces self-tester.md S5's `[PRE]` ordering one-liner.)
|
|
90
|
-
*/
|
|
91
|
-
export function checkPre(testcasesPath: string): CheckResult {
|
|
92
|
-
let d: unknown;
|
|
93
|
-
try {
|
|
94
|
-
d = JSON.parse(fs.readFileSync(testcasesPath, 'utf-8'));
|
|
95
|
-
} catch (e) {
|
|
96
|
-
return { ok: false, message: `testcases.json failed to parse: ${(e as Error).message}` };
|
|
97
|
-
}
|
|
98
|
-
if (!Array.isArray(d)) return { ok: false, message: 'testcases.json not a list' };
|
|
99
|
-
|
|
100
|
-
const pre: number[] = [];
|
|
101
|
-
for (let i = 0; i < d.length; i++) {
|
|
102
|
-
const name = (d[i] as { case_name?: unknown })?.case_name;
|
|
103
|
-
// Parity with the original: a case lacking a string `case_name` is a
|
|
104
|
-
// malformed testcases.json and must fail hard (Python raised KeyError).
|
|
105
|
-
if (typeof name !== 'string') {
|
|
106
|
-
return { ok: false, message: `testcases.json entry at index ${i} missing string case_name` };
|
|
107
|
-
}
|
|
108
|
-
if (name.startsWith('[PRE] ')) pre.push(i);
|
|
109
|
-
}
|
|
110
|
-
const contiguous = pre.every((v, idx) => v === idx);
|
|
111
|
-
if (!contiguous) {
|
|
112
|
-
return {
|
|
113
|
-
ok: false,
|
|
114
|
-
message: `[PRE] entries must be contiguous from index 0, got ${JSON.stringify(pre)}`,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
return { ok: true, message: `OK: ${pre.length} [PRE] entries at front` };
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* The multimodal model api_key must be resolvable along the standard chain
|
|
122
|
-
* (env `HOMETRANS_MODEL_API_KEY` → `~/.hometrans/config.json` autotest block).
|
|
123
|
-
* Delegates entirely to `loadAutotestConfig`, which applies the same env overlay
|
|
124
|
-
* + placeholder validation the runner uses at run time.
|
|
125
|
-
* (Replaces self-tester.md T4's api_key config one-liner.)
|
|
126
|
-
*/
|
|
127
|
-
export function checkConfig(): CheckResult {
|
|
128
|
-
try {
|
|
129
|
-
loadAutotestConfig();
|
|
130
|
-
return { ok: true, message: 'OK' };
|
|
131
|
-
} catch (e) {
|
|
132
|
-
const msg = e instanceof AutotestConfigError ? e.message : (e as Error).message;
|
|
133
|
-
return { ok: false, message: msg };
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Resolve the `test-tools/autotest` directory via the canonical `autotestDir()`
|
|
139
|
-
* chain (env `HOMETRANS_TOOL_PATH` → config.json → tools dir → source-tree
|
|
140
|
-
* walk-up). If that path does not exist, optionally walk up from `fromDir`
|
|
141
|
-
* (the sub-agent's `<output_path>`) for a sibling `test-tools/autotest` (or the
|
|
142
|
-
* legacy `agents/test-tools/autotest`). Prints the resolved dir on success.
|
|
143
|
-
* (Replaces self-tester.md's AutoTest Directory Locator bash tiers.)
|
|
144
|
-
*/
|
|
145
|
-
export function resolveDir(fromDir?: string): CheckResult {
|
|
146
|
-
const dir = autotestDir();
|
|
147
|
-
if (fs.existsSync(dir)) return { ok: true, message: dir };
|
|
148
|
-
|
|
149
|
-
if (fromDir) {
|
|
150
|
-
let d = path.resolve(fromDir);
|
|
151
|
-
for (let i = 0; i < 20 && d; i++) {
|
|
152
|
-
for (const probe of [
|
|
153
|
-
path.join(d, 'test-tools', 'autotest'),
|
|
154
|
-
path.join(d, 'agents', 'test-tools', 'autotest'),
|
|
155
|
-
]) {
|
|
156
|
-
if (fs.existsSync(probe)) return { ok: true, message: probe };
|
|
157
|
-
}
|
|
158
|
-
const parent = path.dirname(d);
|
|
159
|
-
if (parent === d) break;
|
|
160
|
-
d = parent;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return {
|
|
164
|
-
ok: false,
|
|
165
|
-
message: `AutoTest directory not found from HOMETRANS_TOOL_PATH env var or output_path (resolved ${dir})`,
|
|
166
|
-
};
|
|
167
|
-
}
|