@antelopejs/dms 0.20.7 → 0.20.8-next.919.g0c68f67
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/bin/control/commands-verify.mjs +8 -49
- package/bin/control/options.mjs +0 -1
- package/bin/control/run-state.mjs +1 -1
- package/bin/control/timing.mjs +1 -16
- package/bin/control/timing.test.mjs +0 -11
- package/bin/control/verify/decode.mjs +4 -144
- package/bin/control/verify/decode.test.mjs +1 -149
- package/bin/control/verify/formal.mjs +22 -218
- package/bin/control/verify/formal.test.mjs +60 -117
- package/bin/control/verify/map.test.mjs +0 -73
- package/bin/control/verify/types.mjs +4 -18
- package/bin/dms-control.mjs +0 -2
- package/dist/implementations/dms/page/controller.d.ts +2 -1
- package/dist/implementations/dms/page/controller.js.map +1 -1
- package/dist/implementations/dms-builder/engine/connection-access-config.js +2 -2
- package/dist/implementations/dms-builder/engine/connection-targets.js.map +1 -1
- package/dist/implementations/dms-builder/engine/database-access.d.ts +1 -1
- package/dist/implementations/dms-builder/engine/database-access.js +2 -2
- package/dist/implementations/dms-builder/engine/database-check-input.d.ts +3 -2
- package/dist/implementations/dms-builder/engine/database-check-input.js.map +1 -1
- package/dist/implementations/dms-builder/engine/database-check.js +2 -2
- package/dist/implementations/dms-builder/engine/database-check.js.map +1 -1
- package/dist/implementations/dms-builder/engine/probe-answer.d.ts +44 -1
- package/dist/implementations/dms-builder/engine/probe-answer.js +2 -5
- package/dist/implementations/dms-builder/engine/probe-answer.js.map +1 -1
- package/dist/mockup/files.d.ts +1 -1
- package/dist/mockup/files.js +2 -2
- package/dist/pages/settings/users/roles.js.map +1 -1
- package/dist/store/internal/frontend/frontend-ready.d.ts +2 -1
- package/dist/store/internal/frontend/frontend-ready.js.map +1 -1
- package/dist/store/operations.js +4 -4
- package/dist/store/operations.js.map +1 -1
- package/dist/utils/upload-constraints.d.ts +1 -1
- package/dist/utils/upload-constraints.js +2 -2
- package/dist/utils/upload-constraints.js.map +1 -1
- package/dist/validation/issue-message.d.ts +1 -1
- package/dist/validation/issue-message.js +3 -3
- package/dist/validation/issue-message.js.map +1 -1
- package/frontend-vue/layers/dms-core/app/utils/formatter.ts +1 -0
- package/frontend-vue/layers/dms-layout/app/build/composables/navigation/useVisitNavBadges.ts +11 -14
- package/frontend-vue/layers/dms-layout/app/build/composables/settings/security/useSecurityFormat.ts +5 -5
- package/frontend-vue/layers/dms-layout/app/build/utils/modules-catalog.ts +7 -2
- package/frontend-vue/layers/dms-layout/app/build/utils/notificationPayload.ts +9 -5
- package/frontend-vue/layers/dms-layout/app/composables/page/useModuleHistory.ts +4 -1
- package/frontend-vue/layers/dms-layout/app/composables/page/useModulesListing.ts +7 -17
- package/frontend-vue/layers/dms-layout/app/custom-pages/modules.vue +5 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/useMockupCatalog.ts +4 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/useMockupSpec.ts +18 -16
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/usePreviewFrame.ts +2 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/containers/drawerSize.ts +4 -4
- package/frontend-vue/layers/dms-ui/app/build/composables/data-types/relationBadges.ts +2 -5
- package/frontend-vue/layers/dms-ui/app/build/composables/form/fieldComponentProps.ts +2 -2
- package/frontend-vue/layers/dms-ui/app/build/composables/layout/sidePanelState.ts +5 -2
- package/frontend-vue/layers/dms-ui/app/build/composables/period/periodQuery.ts +6 -3
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/tableRowActionValues.ts +13 -13
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/utils/writeError.ts +2 -2
- package/frontend-vue/layers/dms-ui/app/build/utils/blockPreview.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/build/utils/blockPreviewMessages.ts +26 -18
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupCatalog.ts +7 -2
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupSpec.ts +2 -1
- package/frontend-vue/layers/dms-ui/app/components/chart/ApexChartHost.vue +2 -0
- package/frontend-vue/layers/dms-ui/app/composables/useExportJob.ts +2 -2
- package/package.json +9 -8
- package/bin/control/verify/behaviour.mjs +0 -183
- package/bin/control/verify/behaviour.test.mjs +0 -472
- package/bin/control/verify/emit.mjs +0 -539
- package/bin/control/verify/judgement.mjs +0 -101
- package/bin/control/verify/verdict.mjs +0 -327
- package/frontend-vue/scripts/probes/capture-frontend-probe.cjs +0 -23
- package/frontend-vue/scripts/probes/frontend-behavior.cjs +0 -606
- package/frontend-vue/scripts/probes/frontend-legacy.cjs +0 -620
- package/frontend-vue/scripts/probes/frontend-probe-controls.cjs +0 -322
- package/frontend-vue/scripts/prove-comment-emit.mjs +0 -171
- package/frontend-vue/scripts/prove-component-registration.mjs +0 -259
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { mkdtempSync, rmSync, symlinkSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { git } from "../git.mjs";
|
|
6
|
-
import { emitFingerprint } from "./emit.mjs";
|
|
7
|
-
|
|
8
|
-
const DETAIL_LIMIT = 5;
|
|
9
|
-
const OUTPUT_LIMIT = 64 * 1024 * 1024;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param {string} repo The checkout
|
|
13
|
-
* @param {string} sha The commit
|
|
14
|
-
* @returns {string} The scratch worktree
|
|
15
|
-
*/
|
|
16
|
-
function worktreeAt(repo, sha) {
|
|
17
|
-
const dir = mkdtempSync(join(tmpdir(), "dms-control-behaviour-"));
|
|
18
|
-
git(["worktree", "add", "--quiet", "--detach", "--force", dir, sha], repo);
|
|
19
|
-
symlinkSync(join(repo, "node_modules"), join(dir, "node_modules"));
|
|
20
|
-
return dir;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Runs `action` in a throwaway worktree of `sha` whose `node_modules` links
|
|
25
|
-
* the checkout's, then removes it.
|
|
26
|
-
*
|
|
27
|
-
* @param {string} repo The checkout
|
|
28
|
-
* @param {string} sha The commit
|
|
29
|
-
* @param {(dir: string) => Result} action What to run there
|
|
30
|
-
* @returns {Result} What `action` returned
|
|
31
|
-
* @template Result
|
|
32
|
-
*/
|
|
33
|
-
export function inWorktree(repo, sha, action) {
|
|
34
|
-
const dir = worktreeAt(repo, sha);
|
|
35
|
-
try {
|
|
36
|
-
return action(dir);
|
|
37
|
-
} finally {
|
|
38
|
-
git(["worktree", "remove", "--force", dir], repo);
|
|
39
|
-
rmSync(dir, { recursive: true, force: true });
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @param {string} repo The checkout
|
|
45
|
-
* @param {string[]} command The probe command
|
|
46
|
-
* @param {string} sha The commit
|
|
47
|
-
* @returns {string[]} The lines the probe printed
|
|
48
|
-
*/
|
|
49
|
-
function probeFingerprint(repo, command, sha) {
|
|
50
|
-
const [program, ...args] = command;
|
|
51
|
-
return inWorktree(repo, sha, (dir) => {
|
|
52
|
-
const run = spawnSync(program, [...args, dir], {
|
|
53
|
-
cwd: repo,
|
|
54
|
-
encoding: "utf8",
|
|
55
|
-
maxBuffer: OUTPUT_LIMIT,
|
|
56
|
-
});
|
|
57
|
-
if (run.status !== 0)
|
|
58
|
-
throw new Error(
|
|
59
|
-
`behaviour probe ${command.join(" ")} failed on ${sha}:\n${run.stderr}`,
|
|
60
|
-
);
|
|
61
|
-
return run.stdout.split("\n").filter(Boolean);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @param {{ structure: string, text: string }[]} left The items
|
|
67
|
-
* @param {{ structure: string, text: string }[]} right The items to subtract
|
|
68
|
-
* @returns {{ structure: string, text: string }[]} The items of `left` that `right` lacks
|
|
69
|
-
*/
|
|
70
|
-
function difference(left, right) {
|
|
71
|
-
/** @type {Map<string, number>} */
|
|
72
|
-
const counts = new Map();
|
|
73
|
-
for (const item of right)
|
|
74
|
-
counts.set(item.structure, (counts.get(item.structure) ?? 0) + 1);
|
|
75
|
-
return left.filter((item) => {
|
|
76
|
-
const count = counts.get(item.structure) ?? 0;
|
|
77
|
-
if (count === 0) return true;
|
|
78
|
-
counts.set(item.structure, count - 1);
|
|
79
|
-
return false;
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @param {string} path The covered file
|
|
85
|
-
* @param {{ structure: string, text: string }[]} base Its statements at the base
|
|
86
|
-
* @param {{ structure: string, text: string }[]} head Its statements at HEAD
|
|
87
|
-
* @returns {{ removed: string[], added: string[] }} The first statement that differs
|
|
88
|
-
*/
|
|
89
|
-
function sequenceChanges(path, base, head) {
|
|
90
|
-
const length = Math.max(base.length, head.length);
|
|
91
|
-
for (let index = 0; index < length; index += 1) {
|
|
92
|
-
if (base[index]?.structure !== head[index]?.structure) {
|
|
93
|
-
return {
|
|
94
|
-
removed: [
|
|
95
|
-
`${path} statement ${index + 1}: ${base[index]?.text ?? "(none)"}`,
|
|
96
|
-
],
|
|
97
|
-
added: [
|
|
98
|
-
`${path} statement ${index + 1}: ${head[index]?.text ?? "(none)"}`,
|
|
99
|
-
],
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return { removed: [], added: [] };
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* @param {ReturnType<typeof emitFingerprint>} base The fingerprint at the base
|
|
108
|
-
* @param {ReturnType<typeof emitFingerprint>} head The fingerprint at HEAD
|
|
109
|
-
* @returns {{ removed: string[], added: string[] }} What differs
|
|
110
|
-
*/
|
|
111
|
-
function compareEmit(base, head) {
|
|
112
|
-
const removed = difference(base.functions, head.functions).map(
|
|
113
|
-
(item) => `hoisted ${item.text}`,
|
|
114
|
-
);
|
|
115
|
-
const added = difference(head.functions, base.functions).map(
|
|
116
|
-
(item) => `hoisted ${item.text}`,
|
|
117
|
-
);
|
|
118
|
-
for (const path of new Set([
|
|
119
|
-
...Object.keys(base.files),
|
|
120
|
-
...Object.keys(head.files),
|
|
121
|
-
])) {
|
|
122
|
-
const change = sequenceChanges(
|
|
123
|
-
path,
|
|
124
|
-
base.files[path] ?? [],
|
|
125
|
-
head.files[path] ?? [],
|
|
126
|
-
);
|
|
127
|
-
removed.push(...change.removed);
|
|
128
|
-
added.push(...change.added);
|
|
129
|
-
}
|
|
130
|
-
return { removed, added };
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* @param {string[]} base The probe lines at the base
|
|
135
|
-
* @param {string[]} head The probe lines at HEAD
|
|
136
|
-
* @returns {{ removed: string[], added: string[] }} What differs
|
|
137
|
-
*/
|
|
138
|
-
function compareProbe(base, head) {
|
|
139
|
-
/**
|
|
140
|
-
* @param {string[]} list Probe lines
|
|
141
|
-
* @returns {{ structure: string, text: string }[]} The lines as items
|
|
142
|
-
*/
|
|
143
|
-
const lines = (list) => list.map((line) => ({ structure: line, text: line }));
|
|
144
|
-
if (JSON.stringify(base) === JSON.stringify(head))
|
|
145
|
-
return { removed: [], added: [] };
|
|
146
|
-
const removed = difference(lines(base), lines(head)).map((item) => item.text);
|
|
147
|
-
const added = difference(lines(head), lines(base)).map((item) => item.text);
|
|
148
|
-
return removed.length + added.length > 0
|
|
149
|
-
? { removed, added }
|
|
150
|
-
: { removed: ["(order)"], added: ["(order)"] };
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Whether a diff changed the behaviour of the code a formal check covers,
|
|
155
|
-
* decided without judgement. For `emit`, each covered file keeps its
|
|
156
|
-
* top-level statements, in order, with the same structure, and the covered
|
|
157
|
-
* function declarations stay the same wherever they live; for `probe`, the
|
|
158
|
-
* check's probe prints the same lines on a checkout of the base and of HEAD.
|
|
159
|
-
*
|
|
160
|
-
* @param {import("./skill.mjs").Skill} skill The skill
|
|
161
|
-
* @param {Pick<import("./types.mjs").FormalCheck, "covers" | "behaviour">} check The formal check
|
|
162
|
-
* @param {import("./types.mjs").Commits} commits The two commits
|
|
163
|
-
* @returns {import("./types.mjs").BehaviourChange} The decision and what differs
|
|
164
|
-
*/
|
|
165
|
-
export function behaviourChange(skill, check, commits) {
|
|
166
|
-
const probe =
|
|
167
|
-
check.behaviour?.kind === "probe" ? check.behaviour.command : null;
|
|
168
|
-
const change = probe
|
|
169
|
-
? compareProbe(
|
|
170
|
-
probeFingerprint(skill.repo, probe, commits.baseSha),
|
|
171
|
-
probeFingerprint(skill.repo, probe, commits.headSha),
|
|
172
|
-
)
|
|
173
|
-
: compareEmit(
|
|
174
|
-
emitFingerprint(skill.repo, commits.baseSha, check.covers),
|
|
175
|
-
emitFingerprint(skill.repo, commits.headSha, check.covers),
|
|
176
|
-
);
|
|
177
|
-
return {
|
|
178
|
-
method: probe ? `probe ${probe.join(" ")}` : "emit",
|
|
179
|
-
changed: change.removed.length + change.added.length > 0,
|
|
180
|
-
removed: change.removed.slice(0, DETAIL_LIMIT),
|
|
181
|
-
added: change.added.slice(0, DETAIL_LIMIT),
|
|
182
|
-
};
|
|
183
|
-
}
|
|
@@ -1,472 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { execFileSync } from "node:child_process";
|
|
3
|
-
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { dirname, join } from "node:path";
|
|
6
|
-
import test from "node:test";
|
|
7
|
-
import { behaviourChange } from "./behaviour.mjs";
|
|
8
|
-
|
|
9
|
-
const COVERS = ["src/a.ts", "src/b.ts"];
|
|
10
|
-
const IMPORT_OUTPUT = 'import { FAILURE, SUCCESS } from "./output";\n';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @param {string} repo
|
|
14
|
-
* @param {...string} args
|
|
15
|
-
*/
|
|
16
|
-
function git(repo, ...args) {
|
|
17
|
-
return execFileSync("git", args, { cwd: repo, encoding: "utf8" }).trim();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @param {string} repo
|
|
22
|
-
* @param {Record<string, string>} files
|
|
23
|
-
* @param {string} message
|
|
24
|
-
*/
|
|
25
|
-
function commit(repo, files, message) {
|
|
26
|
-
for (const [path, content] of Object.entries(files)) {
|
|
27
|
-
mkdirSync(dirname(join(repo, path)), { recursive: true });
|
|
28
|
-
writeFileSync(join(repo, path), content);
|
|
29
|
-
}
|
|
30
|
-
git(repo, "add", "-A");
|
|
31
|
-
git(
|
|
32
|
-
repo,
|
|
33
|
-
"-c",
|
|
34
|
-
"user.name=t",
|
|
35
|
-
"-c",
|
|
36
|
-
"user.email=t@example.com",
|
|
37
|
-
"-c",
|
|
38
|
-
"commit.gpgsign=false",
|
|
39
|
-
"commit",
|
|
40
|
-
"-q",
|
|
41
|
-
"-m",
|
|
42
|
-
message,
|
|
43
|
-
);
|
|
44
|
-
return git(repo, "rev-parse", "HEAD");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @param {import("node:test").TestContext} t
|
|
49
|
-
* @param {Record<string, string>} base
|
|
50
|
-
* @param {Record<string, string>} head
|
|
51
|
-
* @param {string[]} [covers]
|
|
52
|
-
*/
|
|
53
|
-
function changed(t, base, head, covers = COVERS) {
|
|
54
|
-
const repo = mkdtempSync(join(tmpdir(), "dms-control-emit-test-"));
|
|
55
|
-
t.after(() => rmSync(repo, { recursive: true, force: true }));
|
|
56
|
-
git(repo, "init", "-q");
|
|
57
|
-
const baseSha = commit(repo, base, "base");
|
|
58
|
-
const headSha = commit(repo, head, "head");
|
|
59
|
-
const check = { covers, behaviour: { kind: "emit" } };
|
|
60
|
-
return behaviourChange({ repo }, check, { baseSha, headSha }).changed;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const FUNCTION = "export function add(a, b) {\n return a + b;\n}\n";
|
|
64
|
-
const OUTPUT = {
|
|
65
|
-
"src/output.ts": "export const FAILURE = 1;\nexport const SUCCESS = 0;\n",
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
await test("a function declaration moved verbatim to another covered file is unchanged", (t) => {
|
|
69
|
-
assert.equal(
|
|
70
|
-
changed(
|
|
71
|
-
t,
|
|
72
|
-
{ "src/a.ts": FUNCTION, "src/b.ts": "export const label = 'b';\n" },
|
|
73
|
-
{
|
|
74
|
-
"src/a.ts": 'export { add } from "./b";\n',
|
|
75
|
-
"src/b.ts": `export const label = 'b';\n${FUNCTION}`,
|
|
76
|
-
},
|
|
77
|
-
),
|
|
78
|
-
false,
|
|
79
|
-
);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
await test("an import that moves with its use to another covered file is unchanged", (t) => {
|
|
83
|
-
const use = `${IMPORT_OUTPUT}export function code() {\n return FAILURE + SUCCESS;\n}\n`;
|
|
84
|
-
assert.equal(
|
|
85
|
-
changed(
|
|
86
|
-
t,
|
|
87
|
-
{ ...OUTPUT, "src/a.ts": use, "src/b.ts": "export const label = 1;\n" },
|
|
88
|
-
{
|
|
89
|
-
...OUTPUT,
|
|
90
|
-
"src/a.ts": 'export { code } from "./b";\n',
|
|
91
|
-
"src/b.ts": `export const label = 1;\n${use}`,
|
|
92
|
-
},
|
|
93
|
-
),
|
|
94
|
-
false,
|
|
95
|
-
);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
await test("a comment, a type annotation and a reformat are unchanged", (t) => {
|
|
99
|
-
assert.equal(
|
|
100
|
-
changed(
|
|
101
|
-
t,
|
|
102
|
-
{ "src/a.ts": "const total = [1, 2].reduce((sum, n) => sum + n, 0);\n" },
|
|
103
|
-
{
|
|
104
|
-
"src/a.ts":
|
|
105
|
-
"/** The total. */\nconst total: number = [1, 2].reduce(\n (sum: number, n: number) => (sum + n),\n 0,\n);\n",
|
|
106
|
-
},
|
|
107
|
-
),
|
|
108
|
-
false,
|
|
109
|
-
);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
await test("single quotes against double quotes are unchanged", (t) => {
|
|
113
|
-
assert.equal(
|
|
114
|
-
changed(t, { "src/a.ts": "run('x');\n" }, { "src/a.ts": 'run("x");\n' }),
|
|
115
|
-
false,
|
|
116
|
-
);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
await test("a body edit is changed", (t) => {
|
|
120
|
-
assert.equal(
|
|
121
|
-
changed(
|
|
122
|
-
t,
|
|
123
|
-
{ "src/a.ts": FUNCTION },
|
|
124
|
-
{ "src/a.ts": FUNCTION.replace("a + b", "a - b") },
|
|
125
|
-
),
|
|
126
|
-
true,
|
|
127
|
-
);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
await test("swapping two statements of a covered file is changed", (t) => {
|
|
131
|
-
assert.equal(
|
|
132
|
-
changed(
|
|
133
|
-
t,
|
|
134
|
-
{ "src/a.ts": "await first();\nawait second();\n" },
|
|
135
|
-
{ "src/a.ts": "await second();\nawait first();\n" },
|
|
136
|
-
),
|
|
137
|
-
true,
|
|
138
|
-
);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
await test("moving a statement that is not a function declaration to another covered file is changed", (t) => {
|
|
142
|
-
assert.equal(
|
|
143
|
-
changed(
|
|
144
|
-
t,
|
|
145
|
-
{
|
|
146
|
-
"src/a.ts": "const limit = 0;\nrun(limit);\n",
|
|
147
|
-
"src/b.ts": "run(1);\n",
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
"src/a.ts": "run(limit);\n",
|
|
151
|
-
"src/b.ts": "const limit = 0;\nrun(1);\n",
|
|
152
|
-
},
|
|
153
|
-
),
|
|
154
|
-
true,
|
|
155
|
-
);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
await test("importing the same name under an alias that points elsewhere is changed", (t) => {
|
|
159
|
-
const use = (specifier) =>
|
|
160
|
-
`import { ${specifier} } from "./output";\nexport function code() {\n return CANCELLED + FAILURE;\n}\n`;
|
|
161
|
-
assert.equal(
|
|
162
|
-
changed(
|
|
163
|
-
t,
|
|
164
|
-
{ ...OUTPUT, "src/a.ts": use("CANCELLED, FAILURE") },
|
|
165
|
-
{ ...OUTPUT, "src/a.ts": use("FAILURE as CANCELLED, FAILURE") },
|
|
166
|
-
),
|
|
167
|
-
true,
|
|
168
|
-
);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
await test("importing a binding from another module is changed", (t) => {
|
|
172
|
-
const use = (module) =>
|
|
173
|
-
`import { FAILURE } from "${module}";\nexport function code() {\n return FAILURE;\n}\n`;
|
|
174
|
-
assert.equal(
|
|
175
|
-
changed(
|
|
176
|
-
t,
|
|
177
|
-
{ ...OUTPUT, "src/a.ts": use("./output") },
|
|
178
|
-
{ ...OUTPUT, "src/a.ts": use("./other") },
|
|
179
|
-
),
|
|
180
|
-
true,
|
|
181
|
-
);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
await test("retargeting a re-export is changed", (t) => {
|
|
185
|
-
assert.equal(
|
|
186
|
-
changed(
|
|
187
|
-
t,
|
|
188
|
-
{ "src/a.ts": 'export { add } from "./one";\n' },
|
|
189
|
-
{ "src/a.ts": 'export { add } from "./two";\n' },
|
|
190
|
-
),
|
|
191
|
-
true,
|
|
192
|
-
);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
await test("removing a side-effect import is changed", (t) => {
|
|
196
|
-
assert.equal(
|
|
197
|
-
changed(
|
|
198
|
-
t,
|
|
199
|
-
{ "src/a.ts": 'import "./init";\nrun();\n' },
|
|
200
|
-
{ "src/a.ts": "run();\n" },
|
|
201
|
-
),
|
|
202
|
-
true,
|
|
203
|
-
);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
await test("swapping two assignments to the same field is changed", (t) => {
|
|
207
|
-
assert.equal(
|
|
208
|
-
changed(
|
|
209
|
-
t,
|
|
210
|
-
{ "src/a.ts": "target.value = 1;\ntarget.value = 2;\n" },
|
|
211
|
-
{ "src/a.ts": "target.value = 2;\ntarget.value = 1;\n" },
|
|
212
|
-
),
|
|
213
|
-
true,
|
|
214
|
-
);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
await test("swapping two registrations pushed to the same list is changed", (t) => {
|
|
218
|
-
assert.equal(
|
|
219
|
-
changed(
|
|
220
|
-
t,
|
|
221
|
-
{ "src/a.ts": "handlers.push(first);\nhandlers.push(second);\n" },
|
|
222
|
-
{ "src/a.ts": "handlers.push(second);\nhandlers.push(first);\n" },
|
|
223
|
-
),
|
|
224
|
-
true,
|
|
225
|
-
);
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
await test("importing min instead of max under the same alias, both in covered files, is changed", (t) => {
|
|
229
|
-
const use = (name) =>
|
|
230
|
-
`import { ${name} as pick } from "./b";\nexport function best() {\n return pick(1, 2);\n}\n`;
|
|
231
|
-
const lib = {
|
|
232
|
-
"src/b.ts":
|
|
233
|
-
"export function max(a, b) {\n return a > b ? a : b;\n}\nexport function min(a, b) {\n return a < b ? a : b;\n}\n",
|
|
234
|
-
};
|
|
235
|
-
assert.equal(
|
|
236
|
-
changed(
|
|
237
|
-
t,
|
|
238
|
-
{ ...lib, "src/a.ts": use("max") },
|
|
239
|
-
{ ...lib, "src/a.ts": use("min") },
|
|
240
|
-
),
|
|
241
|
-
true,
|
|
242
|
-
);
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* @param {import("node:test").TestContext} t
|
|
247
|
-
* @param {Record<string, string>} base
|
|
248
|
-
* @param {Record<string, string>} head
|
|
249
|
-
*/
|
|
250
|
-
function changedAll(t, base, head) {
|
|
251
|
-
return changed(t, base, head, Object.keys(base));
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const OPS =
|
|
255
|
-
"export function add(a, b) {\n return a + b;\n}\nexport function sub(a, b) {\n return a - b;\n}\n";
|
|
256
|
-
|
|
257
|
-
await test("retargeting a re-export of a covered module to another of its exports is changed", (t) => {
|
|
258
|
-
assert.equal(
|
|
259
|
-
changedAll(
|
|
260
|
-
t,
|
|
261
|
-
{ "src/ops.ts": OPS, "src/index.ts": 'export { add } from "./ops";\n' },
|
|
262
|
-
{
|
|
263
|
-
"src/ops.ts": OPS,
|
|
264
|
-
"src/index.ts": 'export { sub as add } from "./ops";\n',
|
|
265
|
-
},
|
|
266
|
-
),
|
|
267
|
-
true,
|
|
268
|
-
);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
await test("a re-export of a covered module under its own name, reflowed, is unchanged", (t) => {
|
|
272
|
-
assert.equal(
|
|
273
|
-
changedAll(
|
|
274
|
-
t,
|
|
275
|
-
{ "src/ops.ts": OPS, "src/index.ts": 'export { add } from "./ops";\n' },
|
|
276
|
-
{ "src/ops.ts": OPS, "src/index.ts": 'export { add } from "./ops";\n\n' },
|
|
277
|
-
),
|
|
278
|
-
false,
|
|
279
|
-
);
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
await test("retargeting a local export alias is changed", (t) => {
|
|
283
|
-
const local = (target) =>
|
|
284
|
-
`function f() {\n return 1;\n}\nfunction g() {\n return 2;\n}\nexport { ${target} as run };\n`;
|
|
285
|
-
assert.equal(
|
|
286
|
-
changedAll(t, { "src/a.ts": local("f") }, { "src/a.ts": local("g") }),
|
|
287
|
-
true,
|
|
288
|
-
);
|
|
289
|
-
assert.equal(
|
|
290
|
-
changedAll(
|
|
291
|
-
t,
|
|
292
|
-
{ "src/a.ts": local("f") },
|
|
293
|
-
{ "src/a.ts": `${local("f")}\n` },
|
|
294
|
-
),
|
|
295
|
-
false,
|
|
296
|
-
);
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
await test("exporting a local under its own name, by keyword or by list, is unchanged", (t) => {
|
|
300
|
-
assert.equal(
|
|
301
|
-
changedAll(
|
|
302
|
-
t,
|
|
303
|
-
{ "src/a.ts": "export const limit = 1;\n" },
|
|
304
|
-
{ "src/a.ts": "const limit = 1;\nexport { limit };\n" },
|
|
305
|
-
),
|
|
306
|
-
false,
|
|
307
|
-
);
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
await test("swapping two side-effect imports is changed", (t) => {
|
|
311
|
-
assert.equal(
|
|
312
|
-
changedAll(
|
|
313
|
-
t,
|
|
314
|
-
{ "src/a.ts": 'import "./first";\nimport "./second";\nrun();\n' },
|
|
315
|
-
{ "src/a.ts": 'import "./second";\nimport "./first";\nrun();\n' },
|
|
316
|
-
),
|
|
317
|
-
true,
|
|
318
|
-
);
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
await test("a function moved verbatim into a file with a different top-level variable of the same name is changed", (t) => {
|
|
322
|
-
const log = "export function report() {\n return Logger.channel;\n}\n";
|
|
323
|
-
assert.equal(
|
|
324
|
-
changedAll(
|
|
325
|
-
t,
|
|
326
|
-
{
|
|
327
|
-
"src/a.ts": `const Logger = { channel: "a" };\nexport const keep = 1;\n${log}`,
|
|
328
|
-
"src/b.ts":
|
|
329
|
-
'const Logger = { channel: "b" };\nexport const other = 1;\n',
|
|
330
|
-
},
|
|
331
|
-
{
|
|
332
|
-
"src/a.ts":
|
|
333
|
-
'const Logger = { channel: "a" };\nexport const keep = 1;\n',
|
|
334
|
-
"src/b.ts": `const Logger = { channel: "b" };\nexport const other = 1;\n${log}`,
|
|
335
|
-
},
|
|
336
|
-
),
|
|
337
|
-
true,
|
|
338
|
-
);
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
await test("a function moved with the variable it reads, or reading it through an import, is judged by that variable", (t) => {
|
|
342
|
-
const log = "export function report() {\n return Logger.channel;\n}\n";
|
|
343
|
-
assert.equal(
|
|
344
|
-
changedAll(
|
|
345
|
-
t,
|
|
346
|
-
{
|
|
347
|
-
"src/a.ts": `export const Logger = { channel: "a" };\n${log}`,
|
|
348
|
-
"src/b.ts": "export const other = 1;\n",
|
|
349
|
-
},
|
|
350
|
-
{
|
|
351
|
-
"src/a.ts": 'export const Logger = { channel: "a" };\n',
|
|
352
|
-
"src/b.ts": `import { Logger } from "./a";\nexport const other = 1;\n${log}`,
|
|
353
|
-
},
|
|
354
|
-
),
|
|
355
|
-
false,
|
|
356
|
-
);
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
await test("an import aliased to a name that a local variable also has is changed when a function switches to the local", (t) => {
|
|
360
|
-
const lib = "export const x = 1;\n";
|
|
361
|
-
const use = (name) =>
|
|
362
|
-
`import { x as y } from "./lib";\nconst x = 2;\nexport function value() {\n return ${name};\n}\n`;
|
|
363
|
-
assert.equal(
|
|
364
|
-
changedAll(
|
|
365
|
-
t,
|
|
366
|
-
{ "src/lib.ts": lib, "src/a.ts": use("y") },
|
|
367
|
-
{ "src/lib.ts": lib, "src/a.ts": use("x") },
|
|
368
|
-
),
|
|
369
|
-
true,
|
|
370
|
-
);
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
const NON_LITERAL_SPECIFIERS = [
|
|
374
|
-
["an identifier", "import x from foo;\nx();\n", "import x from bar;\nx();\n"],
|
|
375
|
-
[
|
|
376
|
-
"a template without substitutions",
|
|
377
|
-
"import x from `./a`;\nx();\n",
|
|
378
|
-
"import x from `./b`;\nx();\n",
|
|
379
|
-
],
|
|
380
|
-
["a numeric literal", "import x from 1;\nx();\n", "import x from 2;\nx();\n"],
|
|
381
|
-
["an export-star identifier", "export * from foo;\n", "export * from bar;\n"],
|
|
382
|
-
[
|
|
383
|
-
"a named re-export identifier",
|
|
384
|
-
"export { a } from foo;\n",
|
|
385
|
-
"export { a } from bar;\n",
|
|
386
|
-
],
|
|
387
|
-
["a call", "import x from a();\nx();\n", "import x from b();\nx();\n"],
|
|
388
|
-
[
|
|
389
|
-
"a template with substitutions",
|
|
390
|
-
"import x from `./${a}`;\nx();\n",
|
|
391
|
-
"import x from `./${b}`;\nx();\n",
|
|
392
|
-
],
|
|
393
|
-
];
|
|
394
|
-
|
|
395
|
-
for (const [kind, base, head] of NON_LITERAL_SPECIFIERS) {
|
|
396
|
-
await test(`retargeting a module specifier written as ${kind} is changed`, (t) => {
|
|
397
|
-
assert.equal(changed(t, { "src/a.ts": base }, { "src/a.ts": head }), true);
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
await test("retargeting an identifier specifier in a Vue script is changed", (t) => {
|
|
402
|
-
const vue = (specifier) =>
|
|
403
|
-
`<template><p/></template>\n<script>import x from ${specifier}; x();</script>\n`;
|
|
404
|
-
assert.equal(
|
|
405
|
-
changed(t, { "src/a.vue": vue("foo") }, { "src/a.vue": vue("bar") }, [
|
|
406
|
-
"src/a.vue",
|
|
407
|
-
]),
|
|
408
|
-
true,
|
|
409
|
-
);
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
const SAME_TEXT_SPECIFIERS = [
|
|
413
|
-
[
|
|
414
|
-
"a bare package against the same name as an identifier",
|
|
415
|
-
'import ts from "typescript";\nts.version;\n',
|
|
416
|
-
"import ts from typescript;\nts.version;\n",
|
|
417
|
-
],
|
|
418
|
-
[
|
|
419
|
-
"a bare package against the same name as a template",
|
|
420
|
-
'import ts from "typescript";\nts.version;\n',
|
|
421
|
-
"import ts from `typescript`;\nts.version;\n",
|
|
422
|
-
],
|
|
423
|
-
[
|
|
424
|
-
"a quoted number against the number",
|
|
425
|
-
'import x from "1";\nx();\n',
|
|
426
|
-
"import x from 1;\nx();\n",
|
|
427
|
-
],
|
|
428
|
-
[
|
|
429
|
-
"a quoted relative path against the same text as a template",
|
|
430
|
-
'import x from "./a";\nx();\n',
|
|
431
|
-
"import x from `./a`;\nx();\n",
|
|
432
|
-
],
|
|
433
|
-
];
|
|
434
|
-
|
|
435
|
-
for (const [kind, base, head] of SAME_TEXT_SPECIFIERS) {
|
|
436
|
-
await test(`${kind} is changed`, (t) => {
|
|
437
|
-
assert.equal(changed(t, { "src/a.ts": base }, { "src/a.ts": head }), true);
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
const EXPRESSION_SPECIFIERS = [
|
|
442
|
-
["a call expression", "import x from a();\nx();\n"],
|
|
443
|
-
[
|
|
444
|
-
"a template literal with substitutions",
|
|
445
|
-
"import x from `./${name}`;\nx();\n",
|
|
446
|
-
],
|
|
447
|
-
];
|
|
448
|
-
|
|
449
|
-
for (const [kind, expression] of EXPRESSION_SPECIFIERS) {
|
|
450
|
-
await test(`a module specifier that is ${kind} is changed against a string on either commit`, (t) => {
|
|
451
|
-
const valid = 'import x from "./a";\nx();\n';
|
|
452
|
-
assert.equal(
|
|
453
|
-
changed(t, { "src/a.ts": valid }, { "src/a.ts": expression }),
|
|
454
|
-
true,
|
|
455
|
-
);
|
|
456
|
-
assert.equal(
|
|
457
|
-
changed(t, { "src/a.ts": expression }, { "src/a.ts": valid }),
|
|
458
|
-
true,
|
|
459
|
-
);
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
await test("reformatting a module specifier that is an expression is unchanged", (t) => {
|
|
464
|
-
assert.equal(
|
|
465
|
-
changed(
|
|
466
|
-
t,
|
|
467
|
-
{ "src/a.ts": "import x from a('1');\nx();\n" },
|
|
468
|
-
{ "src/a.ts": 'import x from (a( "1" ));\nx();\n' },
|
|
469
|
-
),
|
|
470
|
-
false,
|
|
471
|
-
);
|
|
472
|
-
});
|