@buaa_smat/hometrans 26.0.7 → 26.0.8
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/agents/a2h-executor.md +37 -0
- package/env-requirements.json +15 -1
- package/i18n/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +2 -2
- package/i18n/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +1 -1
- package/i18n/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +13 -6
- package/i18n/skills/a2h-app-migrate/SKILL.md +2 -2
- package/i18n/skills/a2h-app-migrate/references/workflow.yaml +27 -4
- package/i18n/skills/a2h-app-migrate/scripts/opencode_depth.mjs +418 -0
- package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -0
- package/i18n/skills/a2h-batch-ui-align/SKILL.md +7 -7
- package/i18n/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -1
- package/i18n/skills/a2h-batch-ui-align/references/cards/state.md +20 -2
- package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +2 -2
- package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +3 -3
- package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +3 -1
- package/i18n/skills/a2h-batch-ui-align/references/incremental-scope.md +2 -2
- package/i18n/skills/a2h-batch-ui-align/references/step3-capture.md +10 -6
- package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +13 -9
- package/i18n/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +59 -7
- package/i18n/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/interactions.mjs +186 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +33 -7
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +83 -22
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +39 -5
- package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +25 -1
- package/i18n/skills/a2h-page-specgen/SKILL.md +1 -1
- package/i18n/skills/a2h-page-specgen/references/gates.md +3 -1
- package/i18n/skills/a2h-page-specgen/references/scenario-authoring.md +11 -11
- package/i18n/skills/a2h-page-specgen/references/spec-template.md +3 -3
- package/i18n/skills/a2h-page-specgen/scripts/contract-calls.mjs +40 -3
- package/i18n/skills/a2h-page-specgen/scripts/entry-evidence.mjs +73 -5
- package/i18n/skills/a2h-page-specgen/scripts/gate.mjs +144 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +10 -10
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +1 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +45 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/entry-evidence.test.mjs +100 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/gate.test.mjs +132 -3
- package/i18n/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +36 -1
- package/i18n/skills/a2h-spec-design-pipeline/SKILL.md +1 -1
- package/i18n/skills/a2h-spec-design-pipeline/references/coding-loop.md +16 -0
- package/i18n/skills/a2h-utg-static/SKILL.md +2 -0
- package/package.json +1 -1
- package/platforms/atomcode/agents/a2h-executor.frontmatter.md +6 -0
- package/platforms/codebuddy/agents/a2h-executor.frontmatter.md +5 -0
- package/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +2 -2
- package/platforms/deveco/agents/a2h-executor.frontmatter.md +7 -0
- package/platforms/deveco/agents/build-fixer.frontmatter.md +0 -2
- package/platforms/deveco/agents/code-reviewer.frontmatter.md +0 -2
- package/platforms/deveco/agents/model-render-worker.frontmatter.md +0 -2
- package/platforms/deveco/agents/model-worker.frontmatter.md +0 -2
- package/platforms/deveco/agents/specgen-worker.frontmatter.md +0 -2
- package/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +1 -1
- package/platforms/opencode/agents/a2h-executor.frontmatter.md +7 -0
- package/platforms/opencode/agents/build-fixer.frontmatter.md +0 -2
- package/platforms/opencode/agents/code-reviewer.frontmatter.md +0 -2
- package/platforms/opencode/agents/model-render-worker.frontmatter.md +0 -2
- package/platforms/opencode/agents/model-worker.frontmatter.md +0 -2
- package/platforms/opencode/agents/specgen-worker.frontmatter.md +0 -2
- package/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +13 -6
- package/skills/a2h-app-migrate/SKILL.md +29 -3
- package/skills/a2h-app-migrate/references/host-rules.md +33 -0
- package/skills/a2h-app-migrate/references/workflow.yaml +24 -4
- package/skills/a2h-app-migrate/scripts/opencode_depth.mjs +418 -0
- package/skills/a2h-app-migrate/test/test_executor_header_sync.mjs +78 -0
- package/skills/a2h-app-migrate/test/test_opencode_depth.mjs +312 -0
- package/skills/a2h-app-migrate/tools/dag.mjs +267 -0
- package/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -0
- package/skills/a2h-batch-ui-align/SKILL.md +7 -7
- package/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -1
- package/skills/a2h-batch-ui-align/references/cards/state.md +20 -2
- package/skills/a2h-batch-ui-align/references/cards/widgets.md +2 -2
- package/skills/a2h-batch-ui-align/references/checker-rules.md +3 -3
- package/skills/a2h-batch-ui-align/references/conversion-procedure.md +3 -1
- package/skills/a2h-batch-ui-align/references/host-dispatch.md +5 -5
- package/skills/a2h-batch-ui-align/references/incremental-scope.md +2 -2
- package/skills/a2h-batch-ui-align/references/step3-capture.md +10 -6
- package/skills/a2h-batch-ui-align/references/step5-convert.md +13 -9
- package/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +59 -7
- package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -0
- package/skills/a2h-batch-ui-align/scripts/group_pass.mjs +3 -2
- package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +139 -23
- package/skills/a2h-batch-ui-align/scripts/host_env.mjs +32 -8
- package/skills/a2h-batch-ui-align/scripts/interactions.mjs +186 -0
- package/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +33 -7
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +83 -22
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +39 -5
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_hit_test.test.mjs +82 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +25 -1
- package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +184 -2
- package/skills/a2h-batch-ui-align/scripts/tests/host_env.test.mjs +33 -0
- package/skills/a2h-batch-ui-align/scripts/tests/interactions.test.mjs +258 -0
- package/skills/a2h-page-specgen/SKILL.md +1 -1
- package/skills/a2h-page-specgen/references/evidence.md +15 -0
- package/skills/a2h-page-specgen/references/gates.md +3 -1
- package/skills/a2h-page-specgen/references/scenario-authoring.md +10 -10
- package/skills/a2h-page-specgen/references/spec-template.md +2 -2
- package/skills/a2h-page-specgen/scripts/contract-calls.mjs +40 -3
- package/skills/a2h-page-specgen/scripts/entry-evidence.mjs +73 -5
- package/skills/a2h-page-specgen/scripts/gate.mjs +141 -0
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +1 -1
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +45 -1
- package/skills/a2h-page-specgen/scripts/test/entry-evidence.test.mjs +100 -0
- package/skills/a2h-page-specgen/scripts/test/gate.test.mjs +104 -3
- package/skills/a2h-resource-convert/references/conversion-rules.md +2 -0
- package/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +36 -1
- package/skills/a2h-resource-convert/scripts/tests/adaptive_icon.test.mjs +42 -0
- package/skills/a2h-spec-design-pipeline/SKILL.md +1 -1
- package/skills/a2h-spec-design-pipeline/references/coding-loop.md +16 -0
- package/skills/a2h-spec-design-pipeline/references/execution-model.md +2 -2
- package/skills/a2h-spec-design-pipeline/references/static-defect-gate.md +5 -1
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleMeta.json +5 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleSet.json +4 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-cn.md +2 -1
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-en.md +3 -1
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-v2-observation-cn.md +105 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-v2-observation-en.md +122 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ArkUIRuntimePitfallCheck.js +4 -4
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ArkUIV2ObservationCheck.js +1862 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/index.js +2 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/package.json +1 -1
- package/skills/a2h-spec-design-pipeline/scripts/dispatch/wait.mjs +15 -2
- package/skills/a2h-spec-design-pipeline/scripts/dispatch.mjs +20 -4
- package/skills/a2h-spec-design-pipeline/scripts/test_arkui_v2_observation.ts +284 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_commands.mjs +32 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_wait.mjs +22 -1
- package/skills/a2h-utg-static/SKILL.md +2 -0
- package/skills/a2h-utg-static/references/extractors.md +16 -0
- package/skills/a2h-utg-static/scripts/run_pipeline.mjs +22 -1
- package/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +4 -0
- package/skills/a2h-utg-static/scripts/tests/test_pr169_review_fixes.mjs +15 -0
- package/skills/a2h-utg-static/scripts/tests/test_view_attachments.mjs +330 -0
- package/skills/a2h-utg-static/scripts/view_attachments.mjs +465 -0
- package/platforms/codebuddy/agents/build-fixer.frontmatter.md +0 -5
- package/platforms/codebuddy/agents/code-reviewer.frontmatter.md +0 -5
- package/platforms/codebuddy/agents/model-render-worker.frontmatter.md +0 -5
- package/platforms/codebuddy/agents/model-worker.frontmatter.md +0 -5
- package/platforms/codebuddy/agents/specgen-worker.frontmatter.md +0 -5
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
*/
|
|
9
9
|
const { ApiPermissionDeclaredCheck } = require('./checker/ApiPermissionDeclaredCheck');
|
|
10
10
|
const { ArkUIRuntimePitfallCheck } = require('./checker/ArkUIRuntimePitfallCheck');
|
|
11
|
+
const { ArkUIV2ObservationCheck } = require('./checker/ArkUIV2ObservationCheck');
|
|
11
12
|
const { PlatformApiContractCheck } = require('./checker/PlatformApiContractCheck');
|
|
12
13
|
const { RoutePageSideEffectImportCheck } = require('./checker/RoutePageSideEffectImportCheck');
|
|
13
14
|
|
|
14
15
|
module.exports = {
|
|
15
16
|
ApiPermissionDeclaredCheck,
|
|
16
17
|
ArkUIRuntimePitfallCheck,
|
|
18
|
+
ArkUIV2ObservationCheck,
|
|
17
19
|
PlatformApiContractCheck,
|
|
18
20
|
RoutePageSideEffectImportCheck,
|
|
19
21
|
};
|
|
@@ -88,7 +88,16 @@ export function refreshBaselines(hmos, state, now = new Date().toISOString()) {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
// One blocking wait is one tool call, and the host queues every completion notification until
|
|
92
|
+
// it returns, so every wait is capped here: maxWaitSec ≤ 300, pollSec ≤ 30 (dispatch.mjs only
|
|
93
|
+
// adds the stderr note for its flags). The background waker sets `background: true` to keep its
|
|
94
|
+
// own per-round maxWaitSec (derived from --interval); it never holds a foreground call.
|
|
95
|
+
// The stop file is checked once per round, so it is seen at most one poll late.
|
|
96
|
+
export const MAX_WAIT_CAP_SEC = 300;
|
|
97
|
+
export const POLL_CAP_SEC = 30;
|
|
98
|
+
export async function waitForChange({ hmos, state, baselineFile, eventFile, maxWaitSec = 120, pollSec = 5, now, stopFile, once = false, background = false }) {
|
|
99
|
+
if (!background) maxWaitSec = Math.min(maxWaitSec, MAX_WAIT_CAP_SEC);
|
|
100
|
+
pollSec = Math.min(pollSec, POLL_CAP_SEC);
|
|
92
101
|
ensureDir(dirname(baselineFile));
|
|
93
102
|
ensureDir(dirname(eventFile));
|
|
94
103
|
const baseNow = Date.parse(now ?? new Date().toISOString());
|
|
@@ -117,6 +126,10 @@ export async function waitForChange({ hmos, state, baselineFile, eventFile, maxW
|
|
|
117
126
|
}
|
|
118
127
|
if (once) return { code: 5 };
|
|
119
128
|
if (elapsed >= maxWaitSec * 1000) return { code: 5 };
|
|
120
|
-
|
|
129
|
+
// never sleep past maxWaitSec or the next unit deadline: a poll longer than either would
|
|
130
|
+
// overrun the wait or report the deadline late (both bounds are > 0 here)
|
|
131
|
+
let napMs = Math.min(pollSec * 1000, maxWaitSec * 1000 - elapsed);
|
|
132
|
+
if (deadline) napMs = Math.min(napMs, Date.parse(deadline) - nowMs);
|
|
133
|
+
await sleep(napMs);
|
|
121
134
|
}
|
|
122
135
|
}
|
|
@@ -13,7 +13,7 @@ import { ensureAttemptDir, promoteAttempt, chunkEvidence, resolverEvidence } fro
|
|
|
13
13
|
import { buildReconcileOutput, planNextActions } from "./dispatch/reconcile.mjs";
|
|
14
14
|
import { branchName, provisionGroup, resetGroup, worktreePath, cleanupGenerations, git, gitRaw } from "./dispatch/worktree.mjs";
|
|
15
15
|
import { landingInfo, plannedChunksDone, groupMergeGuard } from "./dispatch/landing.mjs";
|
|
16
|
-
import { waitForChange, seedBaseline, refreshBaselines } from "./dispatch/wait.mjs";
|
|
16
|
+
import { waitForChange, seedBaseline, refreshBaselines, MAX_WAIT_CAP_SEC, POLL_CAP_SEC } from "./dispatch/wait.mjs";
|
|
17
17
|
import { runWaker } from "./dispatch/waker.mjs";
|
|
18
18
|
import { observeProgress } from "./dispatch/progress.mjs";
|
|
19
19
|
|
|
@@ -54,6 +54,14 @@ function numFlag(name, fallback) {
|
|
|
54
54
|
if (!Number.isFinite(n) || !(n > 0)) { console.error(`invalid --${name}: ${raw}`); process.exit(2); }
|
|
55
55
|
return n;
|
|
56
56
|
}
|
|
57
|
+
// numFlag plus an upper bound: a larger value is clamped (with a stderr note), never refused,
|
|
58
|
+
// so a caller's loop keeps working.
|
|
59
|
+
function clampFlag(name, fallback, cap) {
|
|
60
|
+
const n = numFlag(name, fallback);
|
|
61
|
+
if (n <= cap) return n;
|
|
62
|
+
console.error(`--${name} ${n} clamped to ${cap}`);
|
|
63
|
+
return cap;
|
|
64
|
+
}
|
|
57
65
|
// Integer flags: an empty string or "1.5"/"-1" must not silently become 0 or a width
|
|
58
66
|
// that violates the concurrency invariant (`--concurrency 0` would starve every claim).
|
|
59
67
|
function intFlag(name, fallback, min = 1) {
|
|
@@ -669,10 +677,16 @@ async function waitCommand() {
|
|
|
669
677
|
const eventFile = values["event-file"] ?? p.eventFile("orch");
|
|
670
678
|
ensureDir(dirname(baselineFile));
|
|
671
679
|
ensureDir(dirname(eventFile));
|
|
680
|
+
// One wait is one blocked tool call: while it runs, the host queues every completion
|
|
681
|
+
// notification. A long wait therefore delays every finished agent by up to its length
|
|
682
|
+
// (a trace measured 25-minute self-written waits). Clamp it; exit 5 just loops back.
|
|
683
|
+
const maxWaitSec = clampFlag("max-wait", 120, MAX_WAIT_CAP_SEC);
|
|
684
|
+
// A long poll is a long blind sleep: evidence that lands meanwhile is not seen until it ends.
|
|
685
|
+
const pollSec = clampFlag("poll", 5, POLL_CAP_SEC);
|
|
672
686
|
const r = await waitForChange({
|
|
673
687
|
hmos, state, baselineFile, eventFile,
|
|
674
|
-
maxWaitSec
|
|
675
|
-
pollSec
|
|
688
|
+
maxWaitSec,
|
|
689
|
+
pollSec,
|
|
676
690
|
once: values.once === true,
|
|
677
691
|
stopFile: values["stop-file"],
|
|
678
692
|
now,
|
|
@@ -683,7 +697,8 @@ async function waitCommand() {
|
|
|
683
697
|
async function wakerCommand() {
|
|
684
698
|
const p = paths(hmos);
|
|
685
699
|
const interval = numFlag("interval", 30);
|
|
686
|
-
|
|
700
|
+
// same rule as `wait`: a long poll is a blind sleep (the waker runs in background, so only clamp)
|
|
701
|
+
const poll = clampFlag("poll", 5, POLL_CAP_SEC);
|
|
687
702
|
const runId = foldLedger(hmos).state.runId;
|
|
688
703
|
ensureDir(p.snapshotsDir);
|
|
689
704
|
ensureDir(dirname(p.eventFile("waker")));
|
|
@@ -695,6 +710,7 @@ async function wakerCommand() {
|
|
|
695
710
|
eventFile: p.eventFile("waker"),
|
|
696
711
|
maxWaitSec,
|
|
697
712
|
pollSec: poll,
|
|
713
|
+
background: true, // runs in a background sub-agent: its round length follows --interval
|
|
698
714
|
stopFile: p.stopFile,
|
|
699
715
|
now: new Date().toISOString(),
|
|
700
716
|
});
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// Tests for rules/migration-rules/lib/checker/ArkUIV2ObservationCheck.js:
|
|
2
|
+
// the V2 observation-chain sub-codes, message interpolation order, and the
|
|
3
|
+
// render-read index used by deepWrite / nestedClass.
|
|
4
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import * as os from 'node:os';
|
|
6
|
+
import * as path from 'node:path';
|
|
7
|
+
import { test, type TestContext } from 'node:test';
|
|
8
|
+
import assert from 'node:assert/strict';
|
|
9
|
+
import { createRequire } from 'node:module';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
|
|
12
|
+
const requireFromHere = createRequire(import.meta.url);
|
|
13
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const RULES_DIR = path.join(HERE, '..', 'rules', 'migration-rules');
|
|
15
|
+
|
|
16
|
+
process.env.HOMECHECK_MODULE_PATH = path.join(HERE, 'fixtures', 'homecheck-stub.cjs');
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
ArkUIV2ObservationCheck,
|
|
20
|
+
analyzeV2Observation,
|
|
21
|
+
formatMessage,
|
|
22
|
+
} = requireFromHere(path.join(RULES_DIR, 'lib', 'checker', 'ArkUIV2ObservationCheck.js'));
|
|
23
|
+
|
|
24
|
+
const WARN = 1; // AlertLevel.WARN
|
|
25
|
+
const ERROR = 2; // AlertLevel.ERROR
|
|
26
|
+
|
|
27
|
+
function analyze(files: Record<string, string>) {
|
|
28
|
+
const base = path.join(HERE, '__v2obs_fixture__');
|
|
29
|
+
const scans = Object.entries(files).map(([name, raw]) => ({ filePath: path.join(base, name), raw }));
|
|
30
|
+
return analyzeV2Observation(scans, { projectRoot: base });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function codes(issues: any[]): string[] {
|
|
34
|
+
return issues.map((i) => i.subCode).sort();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function tmpDir(t: TestContext): string {
|
|
38
|
+
const dir = mkdtempSync(path.join(os.tmpdir(), 'a2h-v2-observation-'));
|
|
39
|
+
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
40
|
+
return dir;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function project(t: TestContext, files: Record<string, string>): { root: string; files: string[] } {
|
|
44
|
+
const root = tmpDir(t);
|
|
45
|
+
const paths: string[] = [];
|
|
46
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
47
|
+
const target = path.join(root, rel);
|
|
48
|
+
writeFileSync(target, content, 'utf8');
|
|
49
|
+
paths.push(target);
|
|
50
|
+
}
|
|
51
|
+
return { root, files: paths };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
test('ruleSet / ruleMeta / index registration is consistent', () => {
|
|
55
|
+
const fs = requireFromHere('node:fs');
|
|
56
|
+
const ruleSet = JSON.parse(fs.readFileSync(path.join(RULES_DIR, 'config', 'ruleSet.json'), 'utf8'));
|
|
57
|
+
const ruleMeta = JSON.parse(fs.readFileSync(path.join(RULES_DIR, 'config', 'ruleMeta.json'), 'utf8'));
|
|
58
|
+
assert.equal(ruleSet.rules['@hometrans/arkui-v2-observation'].module, 'ArkUIV2ObservationCheck');
|
|
59
|
+
assert.equal(ruleMeta.rules['@hometrans/arkui-v2-observation'].isGlobal, true);
|
|
60
|
+
const rules = requireFromHere(path.join(RULES_DIR, 'lib', 'index.js'));
|
|
61
|
+
assert.equal(typeof rules.ArkUIV2ObservationCheck, 'function');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('v2-render-read-unobserved: getter reaches a bare @ObservedV2 field', () => {
|
|
65
|
+
const issues = analyze({
|
|
66
|
+
'store.ets': `@ObservedV2\nexport class Store {\n count: number = 0;\n bump(): void { this.count = this.count + 1; }\n get label(): string { return 'n' + this.count; }\n}\nexport const store: Store = new Store();\n`,
|
|
67
|
+
'page.ets': `import { store } from './store';\n@ComponentV2\nexport struct Page {\n build() {\n Text(store.label)\n }\n}\n`,
|
|
68
|
+
});
|
|
69
|
+
assert.deepEqual(codes(issues), ['renderRead']);
|
|
70
|
+
assert.equal(issues[0].severity, WARN);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('v2-render-shadow-state: depth mirrors stack.length and selects the branch', () => {
|
|
74
|
+
const issues = analyze({
|
|
75
|
+
'router.ets': `@ObservedV2\nexport class AppRouter {\n @Trace depth: number = 0;\n private stack: string[] = [];\n push(n: string): void { this.stack.push(n); this.bump(); }\n replaceTop(n: string): void { if (this.stack.length > 0) { this.stack.pop(); } this.push(n); }\n currentRoute(): string { return this.stack.length > 0 ? this.stack[this.stack.length - 1] : ''; }\n private bump(): void { this.depth = this.stack.length; }\n}\nexport const appRouter: AppRouter = new AppRouter();\n`,
|
|
76
|
+
'shell.ets': `import { appRouter } from './router';\n@ComponentV2\nexport struct Shell {\n build() {\n if (appRouter.depth > 0) { this.RouteHost() }\n }\n @Builder RouteHost() {\n if (appRouter.currentRoute() === 'A') { Text('A') }\n }\n}\n`,
|
|
77
|
+
});
|
|
78
|
+
assert.deepEqual(codes(issues), ['shadow']);
|
|
79
|
+
assert.equal(issues[0].severity, ERROR);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('v2-render-shadow-state: a condition without the container read stays silent', () => {
|
|
83
|
+
const issues = analyze({
|
|
84
|
+
'router.ets': `@ObservedV2\nexport class AppRouter {\n @Trace depth: number = 0;\n private stack: string[] = [];\n push(n: string): void { this.stack.push(n); this.bump(); }\n private bump(): void { this.depth = this.stack.length; }\n}\nexport const appRouter: AppRouter = new AppRouter();\n`,
|
|
85
|
+
'shell.ets': `import { appRouter } from './router';\n@ComponentV2\nexport struct Shell {\n build() {\n if (appRouter.depth > 0) { Text('non-empty') }\n }\n}\n`,
|
|
86
|
+
});
|
|
87
|
+
assert.deepEqual(codes(issues), []);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('a shadow mirror without a render branch does not suppress the general read', () => {
|
|
91
|
+
const issues = analyze({
|
|
92
|
+
'router.ets': `@ObservedV2\nexport class AppRouter {\n @Trace depth: number = 0;\n stack: string[] = [];\n push(n: string): void { this.stack.push(n); this.bump(); }\n currentRoute(): string { return this.stack.length > 0 ? this.stack[this.stack.length - 1] : ''; }\n private bump(): void { this.depth = this.stack.length; }\n}\nexport const appRouter: AppRouter = new AppRouter();\n`,
|
|
93
|
+
'shell.ets': `import { appRouter } from './router';\n@ComponentV2\nexport struct Shell {\n build() {\n Text(appRouter.currentRoute())\n }\n}\n`,
|
|
94
|
+
});
|
|
95
|
+
assert.deepEqual(codes(issues), ['renderRead']);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('v2-deep-write-unobserved: @Param deep write into a bare @Trace field', () => {
|
|
99
|
+
const issues = analyze({
|
|
100
|
+
'model.ets': `@ObservedV2\nexport class Item {\n @Trace name: string = '';\n count: number = 0;\n}\n@ObservedV2\nexport class Cart {\n items: Item[] = [];\n}\n`,
|
|
101
|
+
'page.ets': `import { Cart } from './model';\n@ComponentV2\nexport struct CartPage {\n @Param cart: Cart = new Cart();\n build() { Text(String(this.cart.items[0].count)) }\n inc() { this.cart.items[0].count = 1; }\n}\n`,
|
|
102
|
+
});
|
|
103
|
+
assert.ok(codes(issues).includes('deepWrite'));
|
|
104
|
+
assert.equal(issues.find((i: any) => i.subCode === 'deepWrite').severity, ERROR);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('v2-deep-write-unobserved: an internal write that the UI never reads stays silent', () => {
|
|
108
|
+
const issues = analyze({
|
|
109
|
+
'model.ets': `@ObservedV2\nexport class Item {\n @Trace name: string = '';\n count: number = 0;\n}\n@ObservedV2\nexport class Cart {\n items: Item[] = [];\n dirty: boolean = false;\n}\n`,
|
|
110
|
+
'page.ets': `import { Cart } from './model';\n@ComponentV2\nexport struct CartPage {\n @Param cart: Cart = new Cart();\n build() { Text(String(this.cart.items.length)) }\n mark() { this.cart.dirty = true; }\n}\n`,
|
|
111
|
+
});
|
|
112
|
+
assert.deepEqual(codes(issues), []);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('v2-nested-class-unobserved: a nested data class without @ObservedV2', () => {
|
|
116
|
+
const issues = analyze({
|
|
117
|
+
'model.ets': `export class Item {\n name: string = '';\n count: number = 0;\n}\n@ObservedV2\nexport class Cart {\n items: Item[] = [];\n}\n`,
|
|
118
|
+
'page.ets': `import { Cart } from './model';\n@ComponentV2\nexport struct CartPage {\n @Param cart: Cart = new Cart();\n build() { Text(String(this.cart.items.length)) }\n inc() { this.cart.items[0].count = 1; }\n}\n`,
|
|
119
|
+
});
|
|
120
|
+
assert.deepEqual(codes(issues), ['nestedClass']);
|
|
121
|
+
assert.equal(issues[0].severity, WARN);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('v2-nested-class-unobserved: @ObservedV2 + @Trace on every layer is silent', () => {
|
|
125
|
+
const issues = analyze({
|
|
126
|
+
'model.ets': `@ObservedV2\nexport class Item {\n @Trace name: string = '';\n @Trace count: number = 0;\n}\n@ObservedV2\nexport class Cart {\n @Trace items: Item[] = [];\n}\n`,
|
|
127
|
+
'page.ets': `import { Cart } from './model';\n@ComponentV2\nexport struct CartPage {\n @Param cart: Cart = new Cart();\n build() { Text(String(this.cart.items.length)) }\n inc() { this.cart.items[0].count = 1; }\n}\n`,
|
|
128
|
+
});
|
|
129
|
+
assert.deepEqual(codes(issues), []);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('v2-monitor-deep-collection: a dot-path @Monitor over an element-mutated collection', () => {
|
|
133
|
+
const issues = analyze({
|
|
134
|
+
'form.ets': `@ObservedV2\nexport class Section {\n @Trace rows: string[] = [];\n}\n@ObservedV2\nexport class Form {\n @Trace section: Section = new Section();\n changed: boolean = false;\n @Monitor('section.rows') onRows() { this.changed = true; }\n add() { this.section.rows.push('x'); }\n}\n`,
|
|
135
|
+
});
|
|
136
|
+
assert.deepEqual(codes(issues), ['monitorDeepCollection']);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('v2-monitor-cycle: two monitors write each other', () => {
|
|
140
|
+
const issues = analyze({
|
|
141
|
+
'loop.ets': `@ObservedV2\nexport class Loop {\n @Trace a: number = 0;\n @Trace b: number = 0;\n @Monitor('a') onA() { this.b = this.b + 1; }\n @Monitor('b') onB() { this.a = this.a + 1; }\n}\n`,
|
|
142
|
+
});
|
|
143
|
+
assert.deepEqual(codes(issues), ['monitorCycle', 'monitorCycle']);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('v2-plain-object-state: an interface state node assigned a plain object', () => {
|
|
147
|
+
const issues = analyze({
|
|
148
|
+
'form.ets': `interface Depth { value: number; }\ninterface FormData { name: string; nested: Depth; }\n@ComponentV2\nexport struct FormPage {\n @Local data: FormData = { name: '', nested: { value: 0 } };\n build() { Text(this.data.nested.value.toString()) }\n set() { this.data.nested.value = 1; }\n load() { this.data = { name: 'x', nested: { value: 2 } }; }\n}\n`,
|
|
149
|
+
});
|
|
150
|
+
assert.deepEqual(codes(issues), ['plainObjectState']);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('event-handler reads are not render reads', () => {
|
|
154
|
+
const issues = analyze({
|
|
155
|
+
'store.ets': `@ObservedV2\nexport class Store {\n count: number = 0;\n bump(): void { this.count = this.count + 1; }\n get label(): string { return 'n' + this.count; }\n}\nexport const store: Store = new Store();\n`,
|
|
156
|
+
'page.ets': `import { store } from './store';\n@ComponentV2\nexport struct Page {\n build() {\n Button('b').onClick(() => { const v = store.label; })\n }\n}\n`,
|
|
157
|
+
});
|
|
158
|
+
assert.deepEqual(codes(issues), []);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('command-method reads are not render reads', () => {
|
|
162
|
+
const issues = analyze({
|
|
163
|
+
'store.ets': `@ObservedV2\nexport class Store {\n count: number = 0;\n load(): void { this.count = 1; }\n}\nexport const store: Store = new Store();\n`,
|
|
164
|
+
'page.ets': `import { store } from './store';\n@ComponentV2\nexport struct Page {\n build() {\n Text('x')\n }\n aboutToAppear() { store.load(); }\n}\n`,
|
|
165
|
+
});
|
|
166
|
+
assert.deepEqual(codes(issues), []);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('v2-render-shadow-state: the branch also reads the shadow -> WARN, not ERROR', () => {
|
|
170
|
+
const issues = analyze({
|
|
171
|
+
'router.ets': `@ObservedV2\nexport class AppRouter {\n @Trace depth: number = 0;\n private stack: string[] = [];\n push(n: string): void { this.stack.push(n); this.bump(); }\n replaceTop(n: string): void { if (this.stack.length > 0) { this.stack.pop(); } this.push(n); }\n currentRoute(): string { return this.depth > 0 ? this.stack[this.depth - 1] : ''; }\n private bump(): void { this.depth = this.stack.length; }\n}\nexport const appRouter: AppRouter = new AppRouter();\n`,
|
|
172
|
+
'shell.ets': `import { appRouter } from './router';\n@ComponentV2\nexport struct Shell {\n build() {\n if (appRouter.depth > 0) { this.RouteHost() }\n }\n @Builder RouteHost() {\n if (appRouter.currentRoute() === 'A') { Text('A') }\n }\n}\n`,
|
|
173
|
+
});
|
|
174
|
+
assert.deepEqual(codes(issues), ['shadowSoft']);
|
|
175
|
+
assert.equal(issues[0].severity, WARN);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('v2-monitor-cycle: a dot-path mirror write is not a self-loop', () => {
|
|
179
|
+
const issues = analyze({
|
|
180
|
+
'profile.ets': `@ObservedV2\nexport class Profile {\n @Trace name: string = '';\n}\n@ObservedV2\nexport class State {\n @Trace profile: Profile = new Profile();\n name: string = '';\n @Monitor('profile.name') onName() { this.name = this.profile.name; }\n}\n`,
|
|
181
|
+
});
|
|
182
|
+
assert.deepEqual(codes(issues), []);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test('v2-monitor-cycle: multiple @Monitor paths are parsed and checked', () => {
|
|
186
|
+
const issues = analyze({
|
|
187
|
+
'loop.ets': `@ObservedV2\nexport class Loop {\n @Trace a: number = 0;\n @Trace b: number = 0;\n @Monitor('a', 'b') onBoth() { this.a = this.a + 1; this.b = this.b + 1; }\n}\n`,
|
|
188
|
+
});
|
|
189
|
+
assert.deepEqual(codes(issues), ['monitorCycle', 'monitorCycle']);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('compound writes (++ / +=) count as write evidence', () => {
|
|
193
|
+
const issues = analyze({
|
|
194
|
+
'store.ets': `@ObservedV2\nexport class Store {\n count: number = 0;\n get label(): string { return 'n' + this.count; }\n bump() { this.count++; }\n}\nexport const store: Store = new Store();\n`,
|
|
195
|
+
'page.ets': `import { store } from './store';\n@ComponentV2\nexport struct Page {\n build() { Text(store.label) }\n}\n`,
|
|
196
|
+
});
|
|
197
|
+
assert.deepEqual(codes(issues), ['renderRead']);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test('v2-nested-class-unobserved: a @Trace container does not make the element class observed', () => {
|
|
201
|
+
const issues = analyze({
|
|
202
|
+
'model.ets': `export class Item {\n name: string = '';\n count: number = 0;\n}\n@ObservedV2\nexport class Cart {\n @Trace items: Item[] = [];\n}\n`,
|
|
203
|
+
'page.ets': `import { Cart } from './model';\n@ComponentV2\nexport struct CartPage {\n @Local cart: Cart = new Cart();\n build() { Text(String(this.cart.items[0].count)) }\n inc() { this.cart.items[0].count = 1; }\n}\n`,
|
|
204
|
+
});
|
|
205
|
+
assert.ok(codes(issues).includes('nestedClass'));
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('local callback parameters do not borrow a unique top-level declaration', () => {
|
|
209
|
+
const issues = analyze({
|
|
210
|
+
'model.ets': `export class item {\n name: string = '';\n}\n`,
|
|
211
|
+
'store.ets': `import { item } from './model';\n@ObservedV2\nexport class Store {\n @Trace items: item[] = [];\n}\nexport const store: Store = new Store();\n`,
|
|
212
|
+
'page.ets': `import { store } from './store';\n@ComponentV2\nexport struct Page {\n build() {\n ForEach(store.items, (item: item) => { Text(item.name) })\n }\n}\n`,
|
|
213
|
+
});
|
|
214
|
+
assert.deepEqual(codes(issues), []);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('constructor-only / readonly fields do not count as writes', () => {
|
|
218
|
+
const issues = analyze({
|
|
219
|
+
'model.ets': `@ObservedV2\nexport class Item {\n readonly name: string;\n constructor(n: string) { this.name = n; }\n}\n`,
|
|
220
|
+
'page.ets': `import { Item } from './model';\n@ComponentV2\nexport struct Row {\n @Param item: Item = new Item('');\n build() { Text(this.item.name) }\n}\n`,
|
|
221
|
+
});
|
|
222
|
+
assert.deepEqual(codes(issues), []);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('v2-nested-class-unobserved: a data class with a constructor is still a data class', () => {
|
|
226
|
+
const issues = analyze({
|
|
227
|
+
'model.ets': `export class Item {\n count: number = 0;\n constructor(c: number) { this.count = c; }\n}\n@ObservedV2\nexport class Cart {\n items: Item[] = [];\n}\n`,
|
|
228
|
+
'page.ets': `import { Cart } from './model';\n@ComponentV2\nexport struct CartPage {\n @Param cart: Cart = new Cart();\n build() { Text(String(this.cart.items[0].count)) }\n inc() { this.cart.items[0].count = 1; }\n}\n`,
|
|
229
|
+
});
|
|
230
|
+
assert.ok(codes(issues).includes('nestedClass'));
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test('a method with a compound write is not inlined as read-only', () => {
|
|
234
|
+
const issues = analyze({
|
|
235
|
+
'store.ets': `@ObservedV2\nexport class Store {\n count: number = 0;\n read(): string { this.count++; return 'x'; }\n}\nexport const store: Store = new Store();\n`,
|
|
236
|
+
'page.ets': `import { store } from './store';\n@ComponentV2\nexport struct Page {\n build() { Text(store.read()) }\n}\n`,
|
|
237
|
+
});
|
|
238
|
+
assert.deepEqual(codes(issues), []);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test('chain types resolve from the declaring file, not the render file', () => {
|
|
242
|
+
const issues = analyze({
|
|
243
|
+
'model.ets': `@ObservedV2\nexport class Item {\n @Trace name: string = '';\n count: number = 0;\n}\n@ObservedV2\nexport class Cart {\n items: Item[] = [];\n}\n`,
|
|
244
|
+
'other.ets': `export class Item {\n name: string = '';\n}\n`,
|
|
245
|
+
'page.ets': `import { Cart } from './model';\n@ComponentV2\nexport struct CartPage {\n @Param cart: Cart = new Cart();\n build() { Text(String(this.cart.items[0].count)) }\n inc() { this.cart.items[0].count = 1; }\n}\n`,
|
|
246
|
+
});
|
|
247
|
+
assert.ok(codes(issues).includes('deepWrite'));
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test('v2-monitor-cycle: a guarded clamp is idempotent and stays silent', () => {
|
|
251
|
+
const issues = analyze({
|
|
252
|
+
'clamp.ets': `@ObservedV2\nexport class Value {\n @Trace value: number = 0;\n @Monitor('value') onValue() { if (this.value < 0) { this.value = 0; } }\n}\n`,
|
|
253
|
+
});
|
|
254
|
+
assert.deepEqual(codes(issues), []);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test('v2-render-shadow-state: different instances of the same class do not pair', () => {
|
|
258
|
+
const issues = analyze({
|
|
259
|
+
'router.ets': `@ObservedV2\nexport class AppRouter {\n @Trace depth: number = 0;\n stack: string[] = [];\n currentRoute(): string { return this.stack.length > 0 ? this.stack[this.stack.length - 1] : ''; }\n private bump(): void { this.depth = this.stack.length; }\n}\nexport const routerA: AppRouter = new AppRouter();\nexport const routerB: AppRouter = new AppRouter();\n`,
|
|
260
|
+
'shell.ets': `import { routerA, routerB } from './router';\n@ComponentV2\nexport struct Shell {\n build() {\n if (routerA.depth > 0) { this.RouteHost() }\n }\n @Builder RouteHost() {\n if (routerB.currentRoute() === 'A') { Text('A') }\n }\n}\n`,
|
|
261
|
+
});
|
|
262
|
+
assert.ok(!codes(issues).includes('shadow'));
|
|
263
|
+
assert.ok(!codes(issues).includes('shadowSoft'));
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
test('message templates keep the owner / source order', () => {
|
|
267
|
+
const render = formatMessage('renderRead', ['build', 'Store.count']);
|
|
268
|
+
assert.match(render.en, /render path \(build\) reaches `Store\.count`/);
|
|
269
|
+
assert.match(render.cn, /渲染路径(build)读到 `Store\.count`/);
|
|
270
|
+
const cycle = formatMessage('monitorCycle', ['Loop', 'a', 'a -> b']);
|
|
271
|
+
assert.match(cycle.en, /`Loop`: @Monitor\('a'\)/);
|
|
272
|
+
assert.match(cycle.cn, /`Loop` 上的 @Monitor\('a'\)/);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test('checkScene emits the ordered message and names the @Builder context', (t) => {
|
|
276
|
+
const { files } = project(t, {
|
|
277
|
+
'store.ets': `@ObservedV2\nexport class Store {\n count: number = 0;\n get label(): string { return 'n' + this.count; }\n bump() { this.count = 1; }\n}\nexport const store: Store = new Store();\n`,
|
|
278
|
+
'page.ets': `import { store } from './store';\n@ComponentV2\nexport struct Page {\n build() { this.Rows() }\n @Builder Rows() { Text(store.label) }\n}\n`,
|
|
279
|
+
});
|
|
280
|
+
const checker = new ArkUIV2ObservationCheck();
|
|
281
|
+
checker.checkScene({ getFiles: () => files.map((p) => ({ getFilePath: () => p })) });
|
|
282
|
+
assert.ok(checker.issues.length > 0);
|
|
283
|
+
assert.match(checker.issues[0].message.cn, /渲染路径(@Builder -> method)读到 `Store\.count`/);
|
|
284
|
+
});
|
|
@@ -251,6 +251,28 @@ test("invalid numeric flags are usage errors, not infinite waits", () => {
|
|
|
251
251
|
}
|
|
252
252
|
});
|
|
253
253
|
|
|
254
|
+
test("wait clamps --max-wait above 300 seconds", () => {
|
|
255
|
+
const root = mk();
|
|
256
|
+
ok(run(root, "init", "--wave", "1", "--concurrency", "2", "--run-id", "r-1"));
|
|
257
|
+
const r = run(root, "wait", "--max-wait", "1600", "--once");
|
|
258
|
+
assert.equal(r.status, 5, r.stderr + r.stdout);
|
|
259
|
+
assert.match(r.stderr, /--max-wait 1600 clamped to 300/);
|
|
260
|
+
const quiet = run(root, "wait", "--max-wait", "300", "--once");
|
|
261
|
+
assert.equal(quiet.status, 5, quiet.stderr + quiet.stdout);
|
|
262
|
+
assert.doesNotMatch(quiet.stderr, /clamped/);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test("wait never sleeps past --max-wait, whatever --poll is", () => {
|
|
266
|
+
const root = mk();
|
|
267
|
+
ok(run(root, "init", "--wave", "1", "--concurrency", "2", "--run-id", "r-1"));
|
|
268
|
+
const t0 = Date.now();
|
|
269
|
+
const r = run(root, "wait", "--max-wait", "1", "--poll", "100");
|
|
270
|
+
const ms = Date.now() - t0;
|
|
271
|
+
assert.equal(r.status, 5, r.stderr + r.stdout);
|
|
272
|
+
assert.match(r.stderr, /--poll 100 clamped to 30/);
|
|
273
|
+
assert.ok(ms < 15_000, `wait took ${ms} ms, expected about 1 s`);
|
|
274
|
+
});
|
|
275
|
+
|
|
254
276
|
test("group-worktree refuses a different base for an existing tree", () => {
|
|
255
277
|
const root = mk();
|
|
256
278
|
ok(run(root, "init", "--wave", "1", "--concurrency", "2", "--run-id", "r-1"));
|
|
@@ -475,6 +497,16 @@ test("waker rejects an invalid --poll before doing any work", () => {
|
|
|
475
497
|
}
|
|
476
498
|
});
|
|
477
499
|
|
|
500
|
+
test("waker clamps --poll above 30 seconds", () => {
|
|
501
|
+
const root = mk();
|
|
502
|
+
ok(run(root, "init", "--wave", "1", "--concurrency", "2", "--run-id", "r-1"));
|
|
503
|
+
writeFileSync(join(root, ".hometrans", "dispatch", "waker.stop"), "");
|
|
504
|
+
const r = run(root, "waker", "--poll", "100");
|
|
505
|
+
assert.match(r.stderr, /--poll 100 clamped to 30/);
|
|
506
|
+
const quiet = run(root, "waker", "--poll", "30");
|
|
507
|
+
assert.doesNotMatch(quiet.stderr, /clamped/);
|
|
508
|
+
});
|
|
509
|
+
|
|
478
510
|
test("group-merge removes generations older than the merged one", () => {
|
|
479
511
|
const root = mk();
|
|
480
512
|
ok(run(root, "init", "--wave", "1", "--concurrency", "2", "--run-id", "r-1"));
|
|
@@ -3,7 +3,7 @@ import assert from "node:assert/strict";
|
|
|
3
3
|
import { mkdirSync, mkdtempSync, readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
5
|
import { join } from "node:path";
|
|
6
|
-
import { captureSnapshot, diffSnapshot, seedBaseline, waitForChange } from "./dispatch/wait.mjs";
|
|
6
|
+
import { captureSnapshot, diffSnapshot, seedBaseline, waitForChange, MAX_WAIT_CAP_SEC, POLL_CAP_SEC } from "./dispatch/wait.mjs";
|
|
7
7
|
import { createState, applyEvent, chunkUnitId } from "./dispatch/fold.mjs";
|
|
8
8
|
|
|
9
9
|
const mk = () => { const r = mkdtempSync(join(tmpdir(), "wait-")); mkdirSync(join(r, ".hometrans", "dispatch"), { recursive: true }); return r; };
|
|
@@ -27,6 +27,27 @@ test("nextDeadline produces a deadline event when it is the earliest change", as
|
|
|
27
27
|
assert.ok(existsSync(join(root, ".hometrans", "dispatch", "orch.event.json")));
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
+
test("a poll longer than maxWaitSec is cut at maxWaitSec", async () => {
|
|
31
|
+
const root = mk();
|
|
32
|
+
const s = createState({ runId: "r-1", concurrency: 1, groups: [{ id: 2, chunks: 1 }] });
|
|
33
|
+
const t0 = Date.now();
|
|
34
|
+
const r = await waitForChange({ hmos: root, state: s, baselineFile: join(root, "s.json"), eventFile: join(root, "e.json"), maxWaitSec: 0.2, pollSec: 10, now: iso(0) });
|
|
35
|
+
const ms = Date.now() - t0;
|
|
36
|
+
assert.equal(r.code, 5);
|
|
37
|
+
assert.ok(ms < 5000, `waited ${ms} ms, expected about 200 ms`);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("caps are 300 s / 30 s and a background wait still honors the stop file", async () => {
|
|
41
|
+
assert.equal(MAX_WAIT_CAP_SEC, 300);
|
|
42
|
+
assert.equal(POLL_CAP_SEC, 30);
|
|
43
|
+
const root = mk();
|
|
44
|
+
const s = createState({ runId: "r-1", concurrency: 1, groups: [{ id: 2, chunks: 1 }] });
|
|
45
|
+
const stop = join(root, "stop");
|
|
46
|
+
writeFileSync(stop, "");
|
|
47
|
+
const r = await waitForChange({ hmos: root, state: s, baselineFile: join(root, "s.json"), eventFile: join(root, "e.json"), maxWaitSec: 3600, pollSec: 0.05, now: iso(0), stopFile: stop, background: true });
|
|
48
|
+
assert.equal(r.code, 5);
|
|
49
|
+
});
|
|
50
|
+
|
|
30
51
|
test("stop file yields timeout code 5", async () => {
|
|
31
52
|
const root = mk();
|
|
32
53
|
const stop = join(root, "stop");
|
|
@@ -160,6 +160,7 @@ enumerate continuous parameter values or every combination of independent states
|
|
|
160
160
|
| `compose_widgets.mjs <ws> --project <project> --append` | **always on Compose app**, AFTER `assemble.mjs` | `widgets[]` per node |
|
|
161
161
|
| `view_widgets.mjs <ws> --project <project> --append` | **always on View/Fragment app**, AFTER `assemble.mjs` | `widgets[]` from layout XML |
|
|
162
162
|
| `preference_widgets.mjs <ws> --project <project> --locale <locale> --append` | **when Preference XML pages exist**, AFTER `assemble.mjs` | `widgets[]` from Preference XML |
|
|
163
|
+
| `view_attachments.mjs <ws> --project <project> --append` | **always on a native app**, AFTER `assemble.mjs` | `attachments[]`: project views handed to a non-layout sink (marker, tooltip, empty view), `view_attachments.json` |
|
|
163
164
|
| `phase_plan.mjs <ws>` + `tools/convert_static_utg_to_ui_elements.ts` | LAST | `phase_plan_nodes.json`, `ui_elements.json` |
|
|
164
165
|
| `view_interactions.mjs extract <ws> <project>` / `apply <ws>` | inventory after native widgets; apply before final assemble | reviewed custom panels/UI states; `interaction_audit.json` gaps |
|
|
165
166
|
|
|
@@ -193,6 +194,7 @@ Per-extractor detail (emitted fields, design rationale, refusals, the tests that
|
|
|
193
194
|
- **Preferences (`preference_nav.mjs`)** — check `hosts=` / `hostless=` and `programmatic_clicks=` / `programmatic_dialogs=`. Unresolved constants, shared listener factories and custom modal APIs are left to review/exploration.
|
|
194
195
|
- **Menus (`menu_nav.mjs`)** — often the largest edge source in View apps; check `unclassified=`.
|
|
195
196
|
- **Window surfaces (`window_nav.mjs`)** — PopupWindow / `WindowManager.addView` / non-Fragment sheets / anonymous `new Dialog(`; View-app branch, after `menu_nav`, before `assemble`. Host-less surfaces are dropped to the explorer's `promote_dynamic.mjs`.
|
|
197
|
+
- **Auxiliary views (`view_attachments.mjs`)** — a project View class constructed and handed to anything but a layout container (`chart.setMarker(M(..))`, `chart.marker = M(..)`, through one variable or factory hop) is stamped on the owning page as `attachments[]`, with the sink, receiver and inflated layout. These surfaces are shown by the receiver's own touch handling, so no click listener names them. Structural only (no API names); check `attachments=` vs `hostless=` / `dropped=` and read `view_attachments.json` for drop reasons. Detail: references/extractors.md.
|
|
196
198
|
- **Code-built View pages (`viewpage_nav.mjs`)** — a dispatch function mounting project View classes; captions go to `expected.hint_any`, never `title_any`.
|
|
197
199
|
- **Host indirection (`presenter_nav.mjs`)** and **media browse (`media_browse_nav.mjs`)** — run **in addition** to the normal extractors, never instead.
|
|
198
200
|
|
|
@@ -209,6 +209,22 @@ Emits `window` nodes with `open-overlay` edges from the resolved host page: the
|
|
|
209
209
|
|
|
210
210
|
Accepted structurally: the dispatch function belongs to a page node and mounts a view; each arm constructs a project class that extends a View type or declares a method returning one, and is not itself a page node; >= 2 distinct classes. One `view-page:<Class>` node per arm (`#<const>` suffix when arms share a class with different modes), labelled from the enum constant's first argument (literal or `R.string.*`) and stamped `shell_host`; the caption goes to `expected.hint_any`, never `title_any`, because it is printed on chrome that is on screen for every page. A click listener calling the function with a plain variable (a tab loop) reaches every page; a table constant reaches only its page. A listener in the HOST is persistent chrome, so every page of the table is its source. `var x = Enum.CONST` for the variable the host passes yields one `default` edge host → initial page; the host's fan-out then downgrades it to `host-activity` in assemble. Locked in `tests/test_viewpage_nav.mjs`.
|
|
211
211
|
|
|
212
|
+
### Auxiliary Views (view_attachments.mjs)
|
|
213
|
+
**A project View constructed and handed to another view, not to a layout container**: a chart marker, a tooltip, an empty view, a dialog body. The receiver shows it from its own touch handling (a chart draws its marker on tap-highlight), so the app registers no click listener for it, `view_interactions` (click bindings only) never offers it, and the explorer never taps the host because it is `clickable=false`. Without this stamp the page's interaction was dropped at every stage.
|
|
214
|
+
```bash
|
|
215
|
+
node scripts/view_attachments.mjs <ws> --project <project> --append
|
|
216
|
+
```
|
|
217
|
+
Structural, no API or library name:
|
|
218
|
+
1. **View classes**: the base's last segment is `View` / `ViewGroup` / `*View` / `*Layout` / `*Button`, or is a project view (transitive), or the class has a base and its own body (nested classes blanked) calls an unqualified `findViewById` or inflates into `this`. Names or bases ending in `Fragment`, `Activity`, `Adapter`, `ViewHolder`, `Decoration`, `Dialog`, `Listener`, ... are never views. A class with no base cannot call `findViewById` unqualified, so body evidence alone does not count there (a wrapper whose nested marker class does).
|
|
219
|
+
2. **Construction sites**: Java `new X(..)` only, Kotlin `X(..)` only; declarations, Java constructors and Kotlin supertype calls are not constructions. Comments and string literals are masked first.
|
|
220
|
+
3. **Sinks**, with one variable hop (`val m = X(..)` ... `chart.marker = m`; a local's uses are looked up in its own function only, a field's in the whole file) and one factory hop (`fun mk() = X(..)`, `return new X(..)` ... `chart.setMarker(mk())`; the call counts only receiver-less in the factory's own file or qualified by its declaring class / object / companion, since a bare name such as `getView(` also matches unrelated methods, and an overriding factory (`override fun`, `@Override` on the factory's own declaration) is called by the framework, so it has no call site):
|
|
221
|
+
- `call-arg`: `chart.setMarker(X(..))`, with the receiver text, or the `apply {}` / `run {}` / `with(c) {}` receiver for an implicit call in any first-level statement of that block (`also {}` / `let {}` take the receiver as `it`, so they give none);
|
|
222
|
+
- `prop-assign`: `chart.marker = X(..)`, or `marker = X(..)` inside `apply {}` / `run {}` / `with(c) {}`.
|
|
223
|
+
|
|
224
|
+
Dropped and counted, never stamped: layout containers (`addView`, `setContentView`, `addHeaderView`, ...: `layout:<callee>`), collections (`add`, `listOf`, ...: `collection:<callee>`), constructor arguments (`Holder(X(..))`: `ctor-arg:<Class>`; a window body is `window_nav`'s), calls on a class name, i.e. static utilities (`Log.d(TAG, v)`, `TextUtils.isEmpty(v)`: `static:<Class>.<fn>`), a variable or factory with no attaching use, and sites in a class no page owns (`hostless`).
|
|
225
|
+
|
|
226
|
+
The host is the page owning the SINK's class, resolved with `view_interactions`' `EvidenceIndex` (so a helper class constructed by a page inherits it). Each `attachments[]` entry: `{at, view_class, view_class_at, base, evidence[], layout?, sink: {kind, callee|target, receiver?, at}, via_var?, via_fn?}`; `layout` is the `R.layout.*` passed to the constructor, resolved to its file. `view_attachments.json` lists every site with its drop reason. Stderr: `view_classes= constructions= attachments= hostless= dropped=`. Not covered: a library view constructed directly (no project subclass), XML data-binding (`app:marker="@{..}"`), reflection / DI. `run_pipeline` runs it as an optional stage: a failure drops `view_attachments.json` and the `attachments` stamps and the pipeline continues. A rerun with `--append` replaces the stamps, clearing them from nodes whose attachment went away. Locked in `tests/test_view_attachments.mjs`.
|
|
227
|
+
|
|
212
228
|
### Host-Indirection Pages (presenter_nav.mjs)
|
|
213
229
|
**Leanback / older-MVP shape** (many presenters vs few Activities):
|
|
214
230
|
```bash
|
|
@@ -425,6 +425,8 @@ export function plan(project, ws, packageName, ev, opts = {}) {
|
|
|
425
425
|
if (native) {
|
|
426
426
|
add(s('activity_widgets', ws, '--project', project, '--append'),
|
|
427
427
|
'always (Activity nodes are invisible to both widget extractors)');
|
|
428
|
+
add(s('view_attachments', ws, '--project', project, '--append'),
|
|
429
|
+
'always on a native app: project views handed to a non-layout sink (marker, tooltip, empty view)');
|
|
428
430
|
}
|
|
429
431
|
if (uniapp) {
|
|
430
432
|
add(s('uniapp_widgets', ws, '--project', project, '--append'), "uni-app app: controls from each page's own <template>");
|
|
@@ -461,11 +463,30 @@ export function plan(project, ws, packageName, ev, opts = {}) {
|
|
|
461
463
|
* Stages whose failure skips only their own output, not the pipeline: the files they write and the
|
|
462
464
|
* node fields they stamp on utg.json (removed, so no later step reads a stale or half-written one).
|
|
463
465
|
*/
|
|
464
|
-
export const OPTIONAL_STAGES = new Map([
|
|
466
|
+
export const OPTIONAL_STAGES = new Map([
|
|
467
|
+
['data_model', { files: ['data_model.json'], nodeFields: ['data_requirements', 'data_needs', 'data_path_conflicts'] }],
|
|
468
|
+
// Heuristic enrichment (regex over source): a code shape it cannot parse must not stop the UTG. It stamps
|
|
469
|
+
// nodes.jsonl, which the next assemble copies into utg.json, so a stale stamp is dropped from both.
|
|
470
|
+
['view_attachments', { files: ['view_attachments.json'], nodeFields: ['attachments'], nodesJsonl: true }],
|
|
471
|
+
]);
|
|
465
472
|
|
|
466
473
|
/** Drop an optional stage's outputs after it failed. */
|
|
467
474
|
export function _dropStageOutputs(ws, spec) {
|
|
468
475
|
for (const fn of spec.files) { const fp = osJoin(ws, fn); if (_exists(fp)) { fs.unlinkSync(fp); } }
|
|
476
|
+
const jsonl = osJoin(ws, 'nodes.jsonl');
|
|
477
|
+
if (spec.nodesJsonl && spec.nodeFields.length && _exists(jsonl)) {
|
|
478
|
+
const lines = readText(jsonl, { encoding: 'utf-8' }).split('\n');
|
|
479
|
+
let dirty = false;
|
|
480
|
+
const out = lines.map((l) => {
|
|
481
|
+
if (!l.trim()) { return l; }
|
|
482
|
+
const n = jsonLoads(l);
|
|
483
|
+
if (!spec.nodeFields.some((f) => Object.hasOwn(n, f))) { return l; }
|
|
484
|
+
for (const f of spec.nodeFields) { delete n[f]; }
|
|
485
|
+
dirty = true;
|
|
486
|
+
return jsonDumps(n, { ensure_ascii: false });
|
|
487
|
+
});
|
|
488
|
+
if (dirty) { writeText(jsonl, out.join('\n')); }
|
|
489
|
+
}
|
|
469
490
|
const utg = osJoin(ws, 'utg.json');
|
|
470
491
|
if (!spec.nodeFields.length || !_exists(utg)) { return; }
|
|
471
492
|
const graph = jsonLoads(readText(utg, { encoding: 'utf-8' }));
|
|
@@ -69,6 +69,10 @@ export const _PREFLIGHT_FIXTURES = ['test_view_interactions.mjs', 'test_hybrid_s
|
|
|
69
69
|
// wrong, collapsing a two-level settings tree onto the root fragment. No count-based row can
|
|
70
70
|
// see that, so the fixture is the live gate.
|
|
71
71
|
'test_preference_nesting.mjs',
|
|
72
|
+
// view_attachments: most corpus apps construct no auxiliary view, so a count row would read 0 and
|
|
73
|
+
// stay green with the sink forms (property assignment, apply-receiver, variable / factory hop)
|
|
74
|
+
// deleted. The fixture locks each form and each drop reason.
|
|
75
|
+
'test_view_attachments.mjs',
|
|
72
76
|
// Covers XML comment masking and programmatic setOnPreferenceClickListener modal recovery;
|
|
73
77
|
// corpus count metrics cannot lock these ownership/false-positive behaviours.
|
|
74
78
|
];
|
|
@@ -170,3 +170,18 @@ test('a failed optional data_model stage removes its file and the stamps it put
|
|
|
170
170
|
assert.deepEqual(JSON.parse(fs.readFileSync(path.join(td, 'utg.json'), 'utf8')).nodes, [{ id: 'a', label: 'A' }, { id: 'b' }]);
|
|
171
171
|
} finally { fs.rmSync(td, { recursive: true, force: true }); }
|
|
172
172
|
});
|
|
173
|
+
|
|
174
|
+
test('a failed optional view_attachments stage removes its file and its stamps from nodes.jsonl and utg.json', () => {
|
|
175
|
+
const [td] = project({
|
|
176
|
+
'view_attachments.json': '{}',
|
|
177
|
+
'nodes.jsonl': `${JSON.stringify({ id: 'a', attachments: [1], label: 'A' })}\n${JSON.stringify({ id: 'b' })}\n`,
|
|
178
|
+
'utg.json': JSON.stringify({ nodes: [{ id: 'a', attachments: [1], label: 'A' }, { id: 'b' }] }),
|
|
179
|
+
});
|
|
180
|
+
try {
|
|
181
|
+
_dropStageOutputs(td, OPTIONAL_STAGES.get('view_attachments'));
|
|
182
|
+
assert.equal(fs.existsSync(path.join(td, 'view_attachments.json')), false);
|
|
183
|
+
const jsonl = fs.readFileSync(path.join(td, 'nodes.jsonl'), 'utf8').trim().split('\n').map((l) => JSON.parse(l));
|
|
184
|
+
assert.deepEqual(jsonl, [{ id: 'a', label: 'A' }, { id: 'b' }]);
|
|
185
|
+
assert.deepEqual(JSON.parse(fs.readFileSync(path.join(td, 'utg.json'), 'utf8')).nodes, [{ id: 'a', label: 'A' }, { id: 'b' }]);
|
|
186
|
+
} finally { fs.rmSync(td, { recursive: true, force: true }); }
|
|
187
|
+
});
|