Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/fork-seams.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
]
},
"apps/server/src/serverSettings.ts": {
"why": "Every settings write goes through upstream's patch and write paths here. The fork swaps in its patch (fork/serverSettingsPatch.ts, under upstream's name, so a project's MCP profile a client left out is kept) and calls its save check (fork/serverSettingsWriteCheck.ts) once in each write path. The load decodes the file after fork/settingsFileRead.ts (old auto-update names renamed, an unusable interval left out so it reads as its default). The lines from \"import { renameRetiredAutoUpdateKeys }\" on predate this list and record main as it was when every upstream file began to count (#277); they are to move into apps/server/src/fork/ (follow-up), and the file cannot grow meanwhile.",
"why": "Every settings write goes through upstream's patch and write paths here. The fork swaps in its patch (fork/serverSettingsPatch.ts, under upstream's name, so a project's MCP profile a client left out is kept) and calls its save check (fork/serverSettingsWriteCheck.ts) once in each write path. The load decodes the file after fork/settingsFileRead.ts (old auto-update names renamed, an unusable interval left out so it reads as its default). The lines from \"import { renameRetiredAutoUpdateKeys }\" on predate this list (#277): the load's decode of the file, which the fork report shares and which needs upstream's private decoders here, and the fallback when the file cannot be read. Each listed copy is one the fork adds over upstream; the run from upstream refuses a spare one (#311).",
"added": [
"// Fork: upstream's patch keeping a project's MCP profile a client left out, and the save check.",
"import { applyServerSettingsPatchKeepingForkProjectKeys as applyServerSettingsPatch } from \"./fork/serverSettingsPatch.ts\";",
Expand All @@ -59,7 +59,6 @@
"import { renameRetiredAutoUpdateKeys } from \"./cloud/autoUpdateSettings.ts\";",
") {",
"}",
"};",
"/**",
"* The load's decode of a settings file's text: parse, rename retired keys, fill policy defaults,",
"* decode. Pure, so the fork's read-only report (`__fork-report`) decodes exactly as a load does.",
Expand All @@ -80,9 +79,6 @@
"const decoded = decodeSettingsFileText(raw, managed.withDefaults);",
"// The file may hold an opt-out we can no longer read; never resume threads or update on a",
"// guess, even when an admin policy defaults them on (a locked policy value still applies).",
"settings = {",
"...managed.defaults,",
"continueThreadsAfterServerUpdate: false,",
"automaticUpdates: false,"
]
},
Expand Down
103 changes: 95 additions & 8 deletions .github/scripts/fork-seam-check.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,60 @@ function findLostLines(config, { atBase, atHead, upstream, afterRebase = false,
return { reasons, ceilings, rises, notes };
}

/**
* Spare listed "added" copies: room for a line nobody announced. From upstream, a copy the head does
* not add over the base is refused (after a rebase: a note, and `lowered.added` keeps the copies in
* use). A pull request that drops copies lists exactly main's copies less those in `ownFiles`.
*/
function findSpareSeamLines(
files,
{ atBase, atHead, upstream, afterRebase = false, ownFiles, lowered },
) {
const ceilings = [];
const notes = [];
const times = (count) => (count === 1 ? "" : ` ${count}×`);
for (const [file, seam] of Object.entries(files)) {
const base = atBase(file);
const head = atHead(file);
if (base === undefined || head === undefined) continue; // Refused (or noted) elsewhere.
const listed = lineCounts(seam.added.join("\n"));
const baseCounts = lineCounts(base);
const headCounts = lineCounts(head);
if (upstream) {
const used = new Map();
const spare = [];
for (const [line, count] of listed) {
const over = Math.max(0, (headCounts.get(line) ?? 0) - (baseCounts.get(line) ?? 0));
used.set(line, Math.min(count, over));
if (over >= count) continue;
spare.push(
`${file}: "added" lists \`${line}\`${times(count)}, but the fork adds ${over === 0 ? "no copy" : `${over}×`} over upstream; ${over === 0 ? 'remove it from "added"' : `list it ${over}×`} (a spare copy lets a later change add the line unannounced).`,
);
}
if (spare.length > 0) {
lowered?.added.set(file, used);
(afterRebase ? notes : ceilings).push(...spare);
}
continue;
}
if (ownFiles === undefined) continue;
const own = Object.hasOwn(ownFiles, file)
? lineCounts(ownFiles[file].added.join("\n"))
: new Map();
for (const [line, count] of listed) {
const dropped = (baseCounts.get(line) ?? 0) - (headCounts.get(line) ?? 0);
if (dropped <= 0) continue;
const want = Math.max(0, count - dropped);
const has = own.get(line) ?? 0;
if (has === want) continue;
ceilings.push(
`${file}: this change drops${times(dropped)} \`${line}\`, which main's list has${times(count)} under "added": ${want === 0 ? "remove it from" : `list it ${want}× under`} "added" in this change's ${CONFIG} (its list has ${has === 0 ? "none" : `${has}`}; a spare copy lets a later change add the line unannounced, too few fails the next run from upstream).`,
);
}
}
return { ceilings, notes };
}

/**
* Listed seam and pending paths that neither the base nor the head has: nothing there to guard.
* Upstream renamed (or removed) the file, so the list names both paths until the base moves on, and
Expand Down Expand Up @@ -881,10 +935,9 @@ const MOVED_WHY =
'Was "pending": fork-follow moved it here once it had no fork line left, as its "lost" entry still counts upstream lines it loses. No seam line: a fork line goes in a file of the fork\'s own.';

/**
* `text` with `lowered` ({ pending, lost } Maps of counts, `hidden` Set of upstream files) applied, as
* { text, changes }, or undefined when nothing changes. Only lowers; a count at 0 removes the entry; a
* "pending" file with no fork line left moves to "files"; each hidden file stops being a fork file
* (its own "forkFiles" entry goes, or a `!` entry excludes it). Parsed again before it is returned.
* `text` with `lowered` (pending/lost/added Maps, `hidden` Set) applied, as { text, changes }, or
* undefined. Only lowers: a 0 count or spare "added" copy goes, an emptied "pending" file moves to
* "files", a hidden file stops being a fork file ("forkFiles" entry or `!`). Parsed again after.
*/
function lowerList(text, lowered) {
const raw = JSON.parse(text);
Expand Down Expand Up @@ -946,6 +999,26 @@ function lowerList(text, lowered) {
`${file}: "forkFiles" ${what} (upstream has it; a pull request's run took it for a fork file)`,
);
}
// Spare "added" copies go, the first listed copies stay: only narrows what a change may add.
for (const [file, used] of lowered.added ?? []) {
if (!Object.hasOwn(raw.files ?? {}, file)) continue;
const seam = raw.files[file];
const kept = new Map();
const removed = [];
const added = seam.added.filter((item) => {
const line = item.trim();
const count = (kept.get(line) ?? 0) + 1;
kept.set(line, count);
if (count <= (used.get(line) ?? Infinity)) return true;
removed.push(line);
return false;
});
if (removed.length === 0) continue;
changes.push(
`${file}: "added" ${seam.added.length} -> ${added.length} lines (spare: ${removed.map((line) => `\`${line}\``).join(", ")})`,
);
seam.added = added;
}
// Appended through defineProperty: a file named `__proto__` stays an own key.
for (const file of moved) {
Object.defineProperty(raw.files, file, {
Expand Down Expand Up @@ -1059,7 +1132,7 @@ function main(argv) {
const lowered =
parsed.loweredList === undefined
? undefined
: { pending: new Map(), lost: new Map(), hidden: new Set() };
: { pending: new Map(), lost: new Map(), added: new Map(), hidden: new Set() };
const unlisted = findUnlistedChanges(config, {
changed,
atBase,
Expand All @@ -1082,9 +1155,17 @@ function main(argv) {
afterRebase: parsed.afterRebase,
lowered,
});
const spare = findSpareSeamLines(config.files, {
atBase,
atHead,
upstream,
afterRebase: parsed.afterRebase,
ownFiles,
lowered,
});
// A ceiling above the count is fixed by lowering it, not by moving lines: its own hint. A count
// that rose with a rebase names the operator's step in its own text.
const ceilings = [...unlisted.ceilings, ...lost.ceilings];
const ceilings = [...unlisted.ceilings, ...lost.ceilings, ...spare.ceilings];
const rises = [...unlisted.rises, ...lost.rises];
// A pull request's run dates an announcement by the commit whose list judges it (main's): its
// own author sets its own date, and fork-checks' base can be older than the list's commit.
Expand Down Expand Up @@ -1122,7 +1203,12 @@ function main(argv) {
)
: [];
const from = parsed.configRef ? `--config-ref ${configRef}` : upstream ? "the head" : "the base";
const notes = [...findListedGone(config, { atBase, atHead }), ...unlisted.notes, ...lost.notes];
const notes = [
...findListedGone(config, { atBase, atHead }),
...unlisted.notes,
...lost.notes,
...spare.notes,
];
for (const note of notes) console.log(printable(`Note: ${note}`));
if (editsList) {
console.log(
Expand Down Expand Up @@ -1184,7 +1270,7 @@ function main(argv) {
}
if (ceilings.length > 0) {
console.error(
`Lower each "pending" ceiling and "lost" count named above (or remove the entry, or set the value its line names) in ${CONFIG}: in this change's list where the line says so, otherwise with a pull request to main.`,
`Lower each "pending" ceiling and "lost" count, and drop each spare "added" copy, named above (or remove the entry, or set the value its line names) in ${CONFIG}: in this change's list where the line says so, otherwise with a pull request to main.`,
);
}
if (late.length > 0) {
Expand Down Expand Up @@ -1216,6 +1302,7 @@ module.exports = {
findListedGone,
findLostLines,
findSeamBreaches,
findSpareSeamLines,
findStaleSeamLines,
findUnlistedChanges,
forkFileTest,
Expand Down
Loading
Loading