GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(aggregator): reject duplicate saved views on load by dezren39 · Pull Request #4536 · developing-today/code

fix(aggregator): reject duplicate saved views on load #4536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
developing-today merged 2 commits into main from queue/6175-4301-viewsstore-invariants
Nov 8, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

fix(aggregator): reject duplicate saved views on load #4536

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
664bbbe
fix(aggregator): reject duplicate saved views on load
dezren39 Nov 2, 2026
431cf33
fix(aggregator): trimmed name uniqueness + PBT for views cross-row in…
Nov 8, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

48 changes: 45 additions & 3 deletions 48 pm-stack/aggregator/src/views.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,45 @@ function isSavedView(value: unknown): value is SavedView {
);
}

/** Uniqueness key for view names: action input trims names before
* they reach the store (validateViewName), so every uniqueness
* comparison — load validator, save, rename — must compare the
* trimmed, case-insensitive form, or a persisted file can carry
* "Alpha" and " Alpha" for one owner past the load gate
* (CodeRabbit finding, PR #4536). */
function normalizedViewName(name: string): string {
return name.trim().toLowerCase();
}

function crossRowInvariantError(views: readonly SavedView[]): string | null {
const ids = new Set<string>();
const namesByOwner = new Map<string, Set<string>>();
const ownersWithDefault = new Set<string>();

for (const [index, view] of views.entries()) {
if (ids.has(view.id)) return `view row ${index} duplicates id "${view.id}"`;
ids.add(view.id);

let names = namesByOwner.get(view.owner);
if (!names) {
names = new Set<string>();
namesByOwner.set(view.owner, names);
}
const normalizedName = normalizedViewName(view.name);
if (names.has(normalizedName)) {
return `view row ${index} duplicates name "${view.name}" for owner "${view.owner}"`;
}
names.add(normalizedName);

if (view.isDefault) {
if (ownersWithDefault.has(view.owner)) return `view row ${index} adds a second default for owner "${view.owner}"`;
ownersWithDefault.add(view.owner);
}
}

return null;
}

let counter = 0;
export function newViewId(now = new Date()): string {
counter = (counter + 1) % 46656;
Expand Down Expand Up @@ -217,7 +256,10 @@ export class ViewsStore {
if (malformedIndex !== -1) {
throw new Error(`view row ${malformedIndex} does not have the expected SavedView shape`);
}
this.views = rows.filter(isSavedView);
const views = rows.filter(isSavedView);
const invariantError = crossRowInvariantError(views);
if (invariantError) throw new Error(invariantError);
this.views = views;
} catch (err) {
this.views = [];
await this.quarantine(`is unparseable (${err instanceof Error ? err.message : String(err)})`);
Expand Down Expand Up @@ -274,7 +316,7 @@ export class ViewsStore {
/** Create a view for the owner. Names are unique per owner. */
async save(input: { owner: string; name: string; filters: ViewFilters }): Promise<SavedView> {
await this.load();
if (this.views.some((v) => v.owner === input.owner && v.name.toLowerCase() === input.name.toLowerCase())) {
if (this.views.some((v) => v.owner === input.owner && normalizedViewName(v.name) === normalizedViewName(input.name))) {
throw new Error(`a view named "${input.name}" already exists for this owner`);
}
const now = new Date().toISOString();
Expand All @@ -296,7 +338,7 @@ export class ViewsStore {
await this.load();
const v = this.views.find((x) => x.id === id && x.owner === owner);
if (!v) return null;
if (this.views.some((x) => x.owner === owner && x.id !== id && x.name.toLowerCase() === name.toLowerCase())) {
if (this.views.some((x) => x.owner === owner && x.id !== id && normalizedViewName(x.name) === normalizedViewName(name))) {
throw new Error(`a view named "${name}" already exists for this owner`);
}
v.name = name;
Expand Down
152 changes: 152 additions & 0 deletions 152 pm-stack/aggregator/test/views.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ownerKey,
validateViewFilters,
viewUrl,
type SavedView,
type ViewItemLike,
} from "../src/views.ts";

Expand All @@ -29,6 +30,20 @@ function tmpStore(): { dir: string; file: string; store: ViewsStore } {
return { dir, file, store: new ViewsStore(file) };
}

function persistedView(overrides: Partial<SavedView> = {}): SavedView {
const now = new Date().toISOString();
return {
id: "vw-1",
name: "Alpha",
owner: drewKey,
filters: { repo: "a/b" },
isDefault: false,
createdAt: now,
updatedAt: now,
...overrides,
};
}

describe("views store (#1276)", () => {
test("save -> reload round-trip persists views with filters and timestamps", async () => {
const { file, store } = tmpStore();
Expand Down Expand Up @@ -139,6 +154,143 @@ describe("views store (#1276)", () => {
});
});

test("cross-row invariant violations are quarantined before ambiguous views can be removed", async () => {
const cases: Array<{ name: string; views: SavedView[] }> = [
Comment thread
dezren39 marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

{
name: "duplicate ids",
views: [persistedView({ id: "vw-dup", name: "Gamma" }), persistedView({ id: "vw-dup", name: "Delta" })],
},
{
name: "case-insensitive duplicate names per owner",
views: [persistedView({ id: "vw-a", name: "Alpha" }), persistedView({ id: "vw-b", name: "alpha" })],
},
{
name: "multiple defaults per owner",
views: [
persistedView({ id: "vw-a", isDefault: true }),
persistedView({ id: "vw-b", name: "Beta", isDefault: true }),
],
},
];

for (const { name, views } of cases) {
const { dir, file, store } = tmpStore();
const raw = JSON.stringify({ version: 1, views });
writeFileSync(file, raw);

expect(await store.all(), name).toEqual([]);
const quarantined = readdirSync(dir).filter((entry) => entry.startsWith("views.json.corrupt-"));
expect(quarantined, name).toHaveLength(1);
expect(readFileSync(join(dir, quarantined[0]), "utf8"), name).toBe(raw);
if (name === "duplicate ids") {
expect(await store.remove("vw-dup", drewKey)).toBe(false);
expect(await store.all()).toEqual([]);
}
}
});

test("whitespace-padded duplicate names are quarantined on load and refused on save/rename", async () => {
const { dir, file, store } = tmpStore();
const raw = JSON.stringify({
version: 1,
views: [persistedView({ id: "vw-a", name: "Alpha" }), persistedView({ id: "vw-b", name: " Alpha" })],
});
writeFileSync(file, raw);
expect(await store.all()).toEqual([]);
expect(readdirSync(dir).filter((f) => f.startsWith("views.json.corrupt-"))).toHaveLength(1);

const { store: live } = tmpStore();
await live.save({ owner: drewKey, name: "Alpha", filters: { repo: "a/b" } });
await expect(live.save({ owner: drewKey, name: " alpha ", filters: {} })).rejects.toThrow("already exists");
const other = await live.save({ owner: drewKey, name: "Beta", filters: {} });
await expect(live.rename(other.id, drewKey, "ALPHA ")).rejects.toThrow("already exists");
});

// PBT for the cross-row invariants (Codex P1, PR #4536). Oracle: an
// independent re-derivation of the three invariants over the raw
// rows — ids unique globally; trimmed, case-insensitive names
// unique per owner; at most one default per owner. Generated stores
// draw ids, names, owners, and default flags from small pools so
// collisions (including case/whitespace-only name differences) are
// frequent; the verdict must also be invariant under row order.
test("property: generated stores are accepted iff the oracle finds no cross-row violation", async () => {
function mulberry32(seed: number) {
return () => {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const owners = [drewKey, ownerKey(claude)];
const namePool = ["Alpha", "alpha", " Alpha ", "Beta", "BETA", "beta ", "Gamma", "Delta"];
const idPool = ["vw-1", "vw-2", "vw-3", "vw-4"];

function oracleValid(views: SavedView[]): boolean {
const ids = new Set<string>();
const namesByOwner = new Map<string, Set<string>>();
const defaults = new Set<string>();
for (const v of views) {
if (ids.has(v.id)) return false;
ids.add(v.id);
const key = v.name.trim().toLowerCase();
const names = namesByOwner.get(v.owner) ?? new Set<string>();
if (names.has(key)) return false;
names.add(key);
namesByOwner.set(v.owner, names);
if (v.isDefault) {
if (defaults.has(v.owner)) return false;
defaults.add(v.owner);
}
}
return true;
}

async function verdict(views: SavedView[]): Promise<{ accepted: boolean; raw: string }> {
const { dir, file, store } = tmpStore();
const raw = JSON.stringify({ version: 1, views });
writeFileSync(file, raw);
const loaded = await store.all();
const quarantined = readdirSync(dir).filter((f) => f.startsWith("views.json.corrupt-"));
if (loaded.length === 0 && views.length > 0) {
expect(quarantined).toHaveLength(1);
expect(readFileSync(join(dir, quarantined[0]), "utf8")).toBe(raw);
return { accepted: false, raw };
}
expect(quarantined).toHaveLength(0);
expect(loaded.map((v) => v.id).sort()).toEqual(views.map((v) => v.id).sort());
return { accepted: true, raw };
}

for (let seed = 1; seed <= 120; seed++) {
const rand = mulberry32(seed);
const n = Math.floor(rand() * 7);
const views: SavedView[] = [];
for (let i = 0; i < n; i++) {
views.push(
persistedView({
id: idPool[Math.floor(rand() * idPool.length)],
name: namePool[Math.floor(rand() * namePool.length)],
owner: owners[Math.floor(rand() * owners.length)],
isDefault: rand() < 0.35,
}),
);
}
const expected = oracleValid(views);
const first = await verdict(views);
expect(first.accepted, ).toBe(expected);
// Row-order invariance: a shuffled copy gets the same verdict.
const shuffled = [...views];
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(rand() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
const second = await verdict(shuffled);
expect(second.accepted, ).toBe(expected);
}
});

test("malformed default filters are quarantined instead of becoming a match-all view", async () => {
const { dir, file, store } = tmpStore();
const raw = JSON.stringify({
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.