Compare commits

...

3 Commits

Author SHA1 Message Date
Ashwin Bhatkal
548144b63d chore(e2e): drop the affected.json CODEOWNERS entry 2026-11-26 15:58:16 +05:30
Ashwin Bhatkal
770c471ea0 ci(e2e): fail e2e when affected.json misses a spec folder or page 2026-11-26 15:41:06 +05:30
Ashwin Bhatkal
8214e16248 ci(e2e): map changed files to the e2e specs they affect 2026-11-26 15:41:05 +05:30
6 changed files with 396 additions and 0 deletions

View File

@@ -67,6 +67,9 @@ jobs:
- name: lint
run: |
cd tests/e2e && pnpm lint
- name: test-scripts
run: |
cd tests/e2e && pnpm test:scripts
test:
strategy:
fail-fast: false

138
tests/e2e/affected.json Normal file
View File

@@ -0,0 +1,138 @@
{
"alerts": [
"frontend/src/pages/AlertList",
"frontend/src/pages/CreateAlert",
"frontend/src/pages/EditRules",
"frontend/src/pages/LogsModulePage",
"frontend/src/pages/TracesModulePage"
],
"api-monitoring": [
"frontend/src/pages/ApiMonitoring"
],
"app-shell": [
"frontend/src/pages/DashboardsListPage",
"frontend/src/pages/HomePage",
"frontend/src/pages/Services",
"frontend/src/pages/Settings"
],
"auth": [
"frontend/src/pages/ForgotPassword",
"frontend/src/pages/HomePage",
"frontend/src/pages/Login",
"frontend/src/pages/ResetPassword",
"frontend/src/pages/SignUp"
],
"dashboards": [
"frontend/src/pages/DashboardsListPage",
"frontend/src/pages/DashboardPage",
"frontend/src/pages/HomePage",
"frontend/src/pages/LogsModulePage"
],
"exceptions": [
"frontend/src/pages/AllErrors",
"frontend/src/pages/ErrorDetails",
"frontend/src/pages/TraceDetailsV3"
],
"home": [
"frontend/src/pages/HomePage",
"frontend/src/pages/LogsModulePage"
],
"infra-monitoring": [
"frontend/src/pages/InfrastructureMonitoring"
],
"integrations": [
"frontend/src/pages/IntegrationsDetailsPage",
"frontend/src/pages/IntegrationsModulePage"
],
"llm-o11y": [
"frontend/src/pages/LLMObservability"
],
"logs-explorer": [
"frontend/src/pages/LogsModulePage",
"frontend/src/pages/LogsSettings"
],
"logs-pipelines": [
"frontend/src/pages/LogsModulePage"
],
"messaging-queues": [
"frontend/src/pages/Celery",
"frontend/src/pages/MessagingQueues"
],
"meter": [
"frontend/src/pages/MeterExplorer"
],
"metrics-explorer": [
"frontend/src/pages/DashboardsListPage",
"frontend/src/pages/MetricsExplorer"
],
"noz": [
"frontend/src/pages/AIAssistantPage",
"frontend/src/pages/HomePage",
"frontend/src/pages/LogsModulePage"
],
"onboarding": [
"frontend/src/pages/HomePage",
"frontend/src/pages/OnboardingPageV2",
"frontend/src/pages/OrgOnboarding",
"frontend/src/pages/Services"
],
"public-dashboard": [
"frontend/src/pages/DashboardPage",
"frontend/src/pages/PublicDashboard"
],
"query-builder": [
"frontend/src/pages/CreateAlert",
"frontend/src/pages/DashboardPage",
"frontend/src/pages/EditRules",
"frontend/src/pages/LogsModulePage",
"frontend/src/pages/MetricsExplorer",
"frontend/src/pages/TracesModulePage"
],
"quick-filters": [
"frontend/src/pages/LogsModulePage"
],
"routing": [],
"saved-views": [
"frontend/src/pages/LogsModulePage",
"frontend/src/pages/MeterExplorer",
"frontend/src/pages/MetricsExplorer",
"frontend/src/pages/TracesModulePage"
],
"service-map": [
"frontend/src/modules/Servicemap",
"frontend/src/pages/Services"
],
"services": [
"frontend/src/pages/MetricsApplication",
"frontend/src/pages/ServiceTopLevelOperations",
"frontend/src/pages/Services"
],
"settings": [
"frontend/src/pages/Settings"
],
"sso": [
"frontend/src/pages/Login",
"frontend/src/pages/Settings"
],
"trace-details": [
"frontend/src/pages/TraceDetailsV3"
],
"traces-explorer": [
"frontend/src/pages/TraceDetailsV3",
"frontend/src/pages/TracesModulePage"
],
"traces-funnels": [
"frontend/src/pages/TracesModulePage"
],
"@smoke": [
"frontend/src/modules/Usage",
"frontend/src/pages/ErrorBoundaryFallback",
"frontend/src/pages/License",
"frontend/src/pages/Status",
"frontend/src/pages/Support",
"frontend/src/pages/UnAuthorized",
"frontend/src/pages/WorkspaceAccessRestricted",
"frontend/src/pages/WorkspaceLocked",
"frontend/src/pages/WorkspaceSuspended"
]
}

View File

@@ -27,6 +27,7 @@
"fmt:check": "oxfmt --check .",
"lint": "oxlint .",
"lint:fix": "oxlint . --fix",
"test:scripts": "node scripts/affected.test.mjs",
"typecheck": "tsc --noEmit"
},
"keywords": [

View File

@@ -0,0 +1,206 @@
import fs from 'node:fs';
import path from 'node:path';
import ts from 'typescript';
import { E2E_DIR, REPO_DIR } from './utils.mjs';
const FEATURES = Object.entries(
JSON.parse(fs.readFileSync(path.join(E2E_DIR, 'affected.json'), 'utf8')),
);
export const FEATURE_NAMES = FEATURES.map(([feature]) => feature);
const ROUTER = path.join(REPO_DIR, 'frontend/src/AppRoutes/pageComponents.ts');
const ENTRY = path.join(REPO_DIR, 'frontend/src/index.tsx');
const SPECS_DIR = path.join(E2E_DIR, 'tests');
const E2E_SOURCE = /^tests\/e2e\/(tests|drivers|bootstrap)\/.+\.ts$/;
const SOURCE = /\.[cm]?[jt]sx?$/;
const IGNORED = [
/\.md$/,
/^docs\//,
/^tests\/integration\//,
/^frontend\/\.(storybook|husky)\//,
/^frontend\/src\/(storybook|mocks-server)\//,
/^frontend\/(.*\/)?(__tests__|__mocks__)\//,
/^frontend\/.*\.(test|spec|stories)\.[jt]sx?$/,
];
const isIgnored = (file) => IGNORED.some((pattern) => pattern.test(file));
const relative = (file) => path.relative(REPO_DIR, file);
const isUnder = (file, root) =>
file === root || file.startsWith(`${root}/`) || file.startsWith(`${root}.`);
const featuresOf = (file) =>
FEATURES.filter(([, roots]) => roots.some((root) => isUnder(file, root)));
function importersOf(tsconfigPath) {
const { config } = ts.readConfigFile(tsconfigPath, (file) =>
ts.sys.readFile(file),
);
const { options, fileNames } = ts.parseJsonConfigFileContent(
config,
ts.sys,
path.dirname(tsconfigPath),
);
const cache = ts.createModuleResolutionCache(
path.dirname(tsconfigPath),
(name) => name,
options,
);
const aliases = Object.entries(options.paths ?? {});
const aliasBase = options.pathsBasePath ?? path.dirname(tsconfigPath);
const resolve = (specifier, from) => {
const { resolvedModule } = ts.resolveModuleName(
specifier,
from,
options,
ts.sys,
cache,
);
if (resolvedModule) {
return resolvedModule.isExternalLibraryImport
? undefined
: path.resolve(resolvedModule.resolvedFileName);
}
// TypeScript resolves only modules, so styles and assets are matched here.
const candidates = specifier.startsWith('.')
? [path.resolve(path.dirname(from), specifier)]
: aliases.flatMap(([pattern, targets]) => {
const prefix = pattern.replace(/\*$/, '');
const matches = pattern.endsWith('*')
? specifier.startsWith(prefix)
: specifier === pattern;
return matches
? targets.map((target) =>
path.resolve(
aliasBase,
target.replace('*', specifier.slice(prefix.length)),
),
)
: [];
});
return candidates.find((candidate) =>
fs.statSync(candidate, { throwIfNoEntry: false })?.isFile(),
);
};
const importers = new Map();
for (const file of fileNames) {
const { importedFiles } = ts.preProcessFile(
fs.readFileSync(file, 'utf8'),
true,
true,
);
for (const { fileName } of importedFiles) {
const target = resolve(fileName, file);
if (target) {
if (!importers.has(target)) {
importers.set(target, new Set());
}
importers.get(target).add(path.resolve(file));
}
}
}
return importers;
}
// Walks importers up from `start`. `tops` are files nothing imports; `routes`
// are files imported straight by the router.
function climb(start, importers, isRouter) {
const seen = new Set([start]);
const queue = [start];
const tops = [];
const routes = [];
while (queue.length) {
const file = queue.pop();
const parents = importers.get(file) ?? new Set();
if (!parents.size) {
tops.push(file);
}
for (const parent of parents) {
if (isRouter(parent)) {
routes.push(file);
} else if (!seen.has(parent)) {
seen.add(parent);
queue.push(parent);
}
}
}
return { tops, routes };
}
// Spec files and feature folders a change can affect. `all` is set when any
// changed file can't be traced to them.
export function affected(changedFiles) {
const reasons = [];
const features = new Set();
const specs = new Set();
let frontend;
let e2e;
for (const changed of changedFiles) {
const file = path.join(REPO_DIR, changed);
// A deleted module or style's importers are in the change as well.
const isDeletedImport =
!fs.existsSync(file) &&
(SOURCE.test(changed) || changed.startsWith('frontend/src/'));
if (isIgnored(changed) || isDeletedImport) {
continue;
}
if (changed.startsWith('frontend/')) {
frontend ??= importersOf(path.join(REPO_DIR, 'frontend/tsconfig.json'));
const { tops, routes } = climb(
file,
frontend,
(parent) => parent === ROUTER,
);
// Other tops are dead code, tests or stories. A file outside the module
// graph (config, lockfile, public asset, scss partial) is never traced.
const isModule = SOURCE.test(changed) && changed.startsWith('frontend/src/');
if (tops.includes(ENTRY)) {
reasons.push(`${changed} reaches the app shell`);
} else if (tops.includes(file) && !isModule) {
reasons.push(`${changed} has no importer`);
}
for (const route of routes) {
const matched = featuresOf(relative(route));
if (!matched.length) {
reasons.push(`${changed} reaches ${relative(route)}, unmapped`);
}
matched.forEach(([feature]) => features.add(feature));
}
} else if (E2E_SOURCE.test(changed)) {
e2e ??= importersOf(path.join(E2E_DIR, 'tsconfig.json'));
for (const top of climb(file, e2e, () => false).tops) {
if (top.startsWith(`${SPECS_DIR}/`)) {
specs.add(path.relative(SPECS_DIR, top));
} else {
reasons.push(`${changed} reaches ${relative(top)}`);
}
}
} else {
reasons.push(`${changed} is not traced`);
}
}
return {
all: reasons.length > 0,
reasons,
features: [...features].sort((a, b) => a.localeCompare(b)),
specs: [...specs].sort((a, b) => a.localeCompare(b)),
};
}
// Spec folders and lazily loaded pages that affected.json does not name.
export function unmapped() {
const folders = fs
.readdirSync(SPECS_DIR, { withFileTypes: true })
.filter((entry) => entry.isDirectory() && !FEATURE_NAMES.includes(entry.name))
.map((entry) => entry.name);
const pages = [
...fs
.readFileSync(ROUTER, 'utf8')
.matchAll(/import\(\s*(?:\/\*.*?\*\/\s*)?'([^']+)'/gs),
]
.map(([, specifier]) => `frontend/src/${specifier}`)
.filter((page) => !featuresOf(page).length);
return { folders, pages };
}

View File

@@ -0,0 +1,40 @@
import assert from 'node:assert/strict';
import { affected, unmapped } from './affected.mjs';
assert.deepEqual(
affected(['frontend/src/pages/AlertList/index.tsx']).features,
['alerts'],
'a page change selects the features mapped to its route',
);
for (const file of [
'frontend/.storybook/preview.tsx',
'docs/api/openapi.yml',
]) {
assert.deepEqual(
affected([file]),
{ all: false, reasons: [], features: [], specs: [] },
`${file} selects nothing`,
);
}
assert.deepEqual(
affected(['tests/e2e/drivers/sso.ts']).specs,
['sso/auth-domains.spec.ts'],
'a driver change selects the specs that import it',
);
for (const file of [
'frontend/pnpm-lock.yaml',
'frontend/src/index.tsx',
'pkg/signoz/signoz.go',
]) {
assert.equal(affected([file]).all, true, `${file} runs everything`);
}
assert.deepEqual(
unmapped(),
{ folders: [], pages: [] },
'add these spec folders and pages to tests/e2e/affected.json',
);

View File

@@ -0,0 +1,8 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
export const E2E_DIR = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'..',
);
export const REPO_DIR = path.resolve(E2E_DIR, '../..');