Skip to content

Commit e30dd59

Browse files
committed
fix: match architecture handtest identifiers literally
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 8c47476 commit e30dd59

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

‎graph-ui/tools/handtest-fixes-architecture.mjs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
*/
3434

3535
import { chromium } from 'playwright';
36+
import { architectureNodeSelector, projectNamePattern } from './handtest-locators.mjs';
3637
import { mkdir, writeFile } from 'node:fs/promises';
3738
import { join, resolve } from 'node:path';
3839
import { inflateSync } from 'node:zlib';
@@ -446,7 +447,7 @@ async function hoverSweep(page) {
446447
const hid = [];
447448
let shown = false;
448449
for (const id of ids.slice(0, 14)) {
449-
const chip = page.locator(`button.architecture-node-label[data-node-id="${id.replace(/"/g, '\\"')}"]`).first();
450+
const chip = page.locator(architectureNodeSelector(id)).first();
450451
if (!(await chip.isVisible().catch(() => false))) continue;
451452
await chip.hover({ timeout: 3000 }).catch(() => {});
452453
await wait(450);
@@ -498,7 +499,7 @@ async function k21(page) {
498499

499500
async function switchProject(page, name) {
500501
await page.locator('.atlas-shell details summary', { hasText: PROJECT }).first().click();
501-
const entry = page.locator('.atlas-project-results button', { has: page.locator('.atlas-project-result-name', { hasText: new RegExp(`^${name}$`) }) }).first();
502+
const entry = page.locator('.atlas-project-results button', { has: page.locator('.atlas-project-result-name', { hasText: projectNamePattern(name) }) }).first();
502503
await entry.waitFor({ timeout: 20000 });
503504
await entry.click();
504505
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { literalPattern } from './literal-pattern.mjs';
2+
3+
/** Match one architecture chip by its graph node ID. */
4+
export function architectureNodeSelector(id) {
5+
// CSS strings need escapes for backslashes, quotes, and control characters.
6+
// Terminate each hex escape so the next character cannot extend its code point.
7+
const escaped = id.replace(/[\x00-\x1f\x7f"\\]/g, char => `\\${char.codePointAt(0).toString(16)} `);
8+
return `button.architecture-node-label[data-node-id="${escaped}"]`;
9+
}
10+
11+
/** Match a complete project name in the project chooser. */
12+
export function projectNamePattern(name) {
13+
return literalPattern(name, { start: true, end: true });
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { expect, it } from 'vitest';
2+
import { JSDOM } from 'jsdom';
3+
import { architectureNodeSelector, projectNamePattern } from './handtest-locators.mjs';
4+
5+
it.each(['node', 'node"name', 'node\\name', 'node\\"name', 'node\nname', 'node\rname', 'node\fname', 'node], button'])('selects only the literal graph node ID: %j', id => {
6+
const { document } = new JSDOM('<button class="architecture-node-label" data-node-id="other"></button>').window;
7+
const target = document.createElement('button');
8+
target.className = 'architecture-node-label';
9+
target.setAttribute('data-node-id', id);
10+
document.body.append(target);
11+
expect(document.querySelectorAll(architectureNodeSelector(id))).toHaveLength(1);
12+
expect(document.querySelector(architectureNodeSelector(id))).toBe(target);
13+
});
14+
15+
it.each(['a.b', 'a+b', '(project)', '[project]', 'a\\b', '*', '(a+)+$'])('matches a complete literal project name: %j', name => {
16+
const pattern = projectNamePattern(name);
17+
expect(pattern.test(name)).toBe(true);
18+
expect(pattern.test(`prefix${name}`)).toBe(false);
19+
expect(pattern.test(`${name}suffix`)).toBe(false);
20+
});
21+
22+
it('does not treat a project-name dot as a wildcard', () => {
23+
expect(projectNamePattern('a.b').test('axb')).toBe(false);
24+
});

0 commit comments

Comments
 (0)