Repository navigation
fix(insights): a session id is only unique inside its app (#248) - #532
Conversation
Signed-off-by: snowyukitty <[email protected]>
|
Thank you for digging into #248, @snowyukitty β the With two apps sharing a Three things before I can merge it. 1. The added test passes on for (let i = 0; i < 7; i++) db.insertEvent(event("app-alpha", "s-shared", "pytest test_a.py", i) as any);
for (let i = 0; i < 7; i++) db.insertEvent(event("app-beta", "s-shared", "pytest test_a.py", i) as any);Then assert both 2. The insight 3. Please drop the Also two stray blank lines snuck in β one after Fix 1 and 2, drop 3, and I'll merge this. It's a good catch and I'd rather land it with a test that actually guards the behaviour. Generated by Claude Code |
Review on #532 found the added test green on an unpatched main: its two apps used different session ids, and `GROUP BY session_id, cmd` already told those apart, so it never exercised the grouping it was named for. The fixture now collides on both β one session id, one command, two apps β and on 26ef8bc the loop list comes back holding only `app-alpha:s-shared`. The same review found the grouping fix stopping short of the ids. `loop:`, `spend:` and `errors:` were built from the session id alone, so the two rows the fix correctly separates were handed to `key={i.id}` in Alerts.tsx as one. `rowId` carries the pair the queries group by, encoded rather than joined: an app `a:b` in session `c` and an app `a` in session `b:c` are two rows that a plain join writes as one string, and source_app is not constrained to exclude a colon. A third fixture pair pins that, and the uniqueness assertion fails on a plain join with 9 insights sharing 8 ids. insights-scope.test.ts matched ids by prefix, which the new shape breaks. Its source_app came from splitting an OS path on "/", which does not split a Windows path, so the assertions are now exact against `basename`. The isWithin normalize() change is dropped. It is platform-bound, and the one path shape that does fail today deserves its own PR. Signed-off-by: snowyukitty <[email protected]>
|
Before changing anything I ran the existing test against unpatched 1. The fixture collides now. One session id, one command, two apps. On It carries all three session-scoped insights on that shared id, so the id assertion below covers 2. The ids carry the pair. The fixture produces nine insight rows β three kinds for each of the two colliding apps, two more loops from the pair in the next paragraph, and the hourly burn card. With Three duplicate ids, one for each of One thing changed the shape of the fix: 3. Dropped, with both stray blank lines.
One change you didn't ask for, and can refuse. That file's fixture built A separate Windows finding.
Validation. |
|
All three points check out, and I re-ran each one rather than reading the diff β same standard the first review held itself to. 1. The fixture collides now, and the test earns its name. Reverting only With 2. Exactly the number you reported. The third test fails alongside it at 3. On the id format change, which nobody asked about but is the thing that would bite later: I checked whether anything consumes an insight The And please do open the Windows Also ran: CI on this PR is currently red for an unrelated reason β Thanks for the thorough second pass β the reproduction notes in your reply made this quick to verify. Generated by Claude Code |
Reported by @snowyukitty in SirAllap#569, and it is the separate finding they asked for when the platform-bound half was dropped from SirAllap#532. `insights-scope.test.ts` built the in-scope cwd as `SCOPED + "/wt/x"` while `isWithin` (config.ts) compares against the platform's own separator. On Windows that fixture is `C:\...\scoped/wt/x`, which does not start with `C:\...\scoped\` β so the case that exists to prove a turn is in scope *through the directory it ran in* was, on that platform, proving nothing. Reduced probe with explicit win32 semantics, which runs anywhere: isWithin(scoped + "/wt/x", scoped) -> false (before) isWithin(join(scoped, "wt", "x"), scoped) -> true (after) isWithin(join("C:\\fixture", "other"), scoped) -> false (control) Fixture only. The scoping behaviour it exercises is unchanged, and `join` was already imported. Co-Authored-By: Claude Opus 5 <[email protected]>
What does this PR do?
Fixes the F18 part of #248. A session id is only unique inside the app that
issued it, and the insight queries grouped by session id alone β so two apps
working the same project, each running
pytest test_a.pyseven times, collapsedinto one card,
Possible loop Β· 14Γ identical command, attributed to whicheversource_appSQLite happened to return.GROUP BY source_app, session_id[, cmd]splits the rows. Theideach card iskeyed by carries the pair too: without that, the two rows the grouping fix
correctly separates are handed to
key={i.id}inAlerts.tsxas one, and theUI merges them straight back.
rowIdencodes the pair rather than joining it,because
source_appis not constrained to exclude a colon.The
isWithin/normalize()change from the first revision is dropped. It isplatform-bound, and the one path shape that does fail today belongs in its own
PR with its failing case.
How was it tested?
server/test/insights-group-app.test.tsis built around the collision β onesession id, one command, two apps β and asserts both halves, because each fails
alone:
26ef8bcapp-alpha:s-sharedGROUP BYfixed, ids untouchedThe fixture carries all three session-scoped insights on the shared id, so the
uniqueness assertion covers
spend:anderrors:as well asloop:.server/test/insights-scope.test.tsmatched insight ids by prefix, which the newid shape breaks. Its
source_appcame from splitting an OS path on/, whichdoes not split a Windows path, so it uses
basenamenow and its four assertionsare exact.
Also run:
bun run typecheckinserver/andweb/,bunx vite build, and thefull
serversuite on both26ef8bcand this branch β the five files that touchinsights fail identically on both, and this branch adds three passing tests.