Skip to content

Commit 3e45eaa

Browse files
Merge pull request #269 from RtlZeroMemory/fix/codeql-alerts
fix: reduce CodeQL noise from tests and harden scan findings
2 parents ea6ecca + f9b5576 commit 3e45eaa

File tree

7 files changed

+44
-10
lines changed

7 files changed

+44
-10
lines changed

.github/codeql/codeql-config.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: rezi-codeql
2+
paths-ignore:
3+
- "**/__tests__/**"
4+
- "**/*.test.js"
5+
- "**/*.test.jsx"
6+
- "**/*.test.mjs"
7+
- "**/*.test.ts"
8+
- "**/*.test.tsx"
9+
- "**/tests.rs"

.github/workflows/codeql.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
with:
3131
languages: javascript-typescript
3232
build-mode: none
33+
config-file: ./.github/codeql/codeql-config.yml
3334

3435
- name: Perform CodeQL Analysis
3536
uses: github/codeql-action/analyze@v3
@@ -47,6 +48,7 @@ jobs:
4748
with:
4849
languages: rust
4950
build-mode: none
51+
config-file: ./.github/codeql/codeql-config.yml
5052

5153
- name: Perform CodeQL Analysis
5254
uses: github/codeql-action/analyze@v3

docs/dev/testing.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ Quick scoped run:
157157
node scripts/run-tests.mjs --filter "codeEditor.syntax"
158158
```
159159

160+
`--filter` performs a literal substring match against discovered relative test
161+
file paths. It does not interpret the value as a raw regular expression.
162+
160163
### Manual HSR + GIF Workflow
161164

162165
Use the built-in demos under `scripts/hsr/`:

docs/guide/testing.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Filter to a subset:
2828
node scripts/run-tests.mjs --filter "layout"
2929
```
3030

31+
`--filter` matches a literal substring in the discovered relative test file
32+
paths.
33+
3134
## What to test
3235

3336
- Unit behavior for pure helpers and validators.

packages/core/src/constraints/helpers.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function formatDslNumber(fn: string, value: number): string {
102102
}
103103

104104
if (out.includes(".")) {
105-
out = out.replace(/0+$/, "").replace(/\.$/, "");
105+
out = trimTrailingZerosAfterDecimal(out);
106106
}
107107
if (out.length > 64) {
108108
throw invalidArg(
@@ -113,6 +113,17 @@ function formatDslNumber(fn: string, value: number): string {
113113
return `${sign}${out}`;
114114
}
115115

116+
function trimTrailingZerosAfterDecimal(value: string): string {
117+
let end = value.length;
118+
while (end > 0 && value.charCodeAt(end - 1) === 48) {
119+
end--;
120+
}
121+
if (end > 0 && value.charCodeAt(end - 1) === 46) {
122+
end--;
123+
}
124+
return end === value.length ? value : value.slice(0, end);
125+
}
126+
116127
function metricToRefProp(metric: WidgetMetric): RefProp {
117128
switch (metric) {
118129
case "width":

packages/core/src/widgets/__tests__/compositionWidgets.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ describe("composition widgets", () => {
7171
assert.equal(sidebarBox.props.width, railWidth);
7272
});
7373

74+
test("constraint helpers format exponent inputs as trimmed decimal literals", () => {
75+
const width = widthConstraints.clampedPercentOfParent({
76+
ratio: 1e-7,
77+
min: 2.5e-7,
78+
max: 1e-6,
79+
});
80+
81+
assert.equal(width.source, "clamp(0.00000025, parent.w * 0.0000001, 0.000001)");
82+
});
83+
7484
test("ui.card title overload includes title and body", () => {
7585
const renderer = createTestRenderer({ viewport: { cols: 60, rows: 10 } });
7686
const result = renderer.render(ui.card("Title", [ui.text("body")]));

scripts/run-tests.mjs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ function collectPackageTests(root) {
7171
return out;
7272
}
7373

74+
function escapeRegExpLiteral(value) {
75+
return value.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
76+
}
77+
7478
function parseArgs(argv) {
7579
let scope = "all";
7680
let filter = null;
@@ -146,15 +150,7 @@ if (scope === "packages" && packageTests.length === 0) {
146150
let relFiles = files.map((f) => relative(root, f));
147151

148152
if (typeof filter === "string") {
149-
let rx;
150-
try {
151-
rx = new RegExp(filter);
152-
} catch (err) {
153-
const msg = err instanceof Error ? err.message : String(err);
154-
process.stderr.write(`run-tests: invalid --filter regex: ${msg}\n`);
155-
process.exit(1);
156-
}
157-
153+
const rx = new RegExp(escapeRegExpLiteral(filter));
158154
relFiles = relFiles.filter((p) => rx.test(p));
159155
if (relFiles.length === 0) {
160156
process.stderr.write(`run-tests: --filter matched 0 test files (${filter})\n`);

0 commit comments

Comments
 (0)