six defects, and a typecheck the repo could not pass
Found by reviewing the plugin rather than running it. Nothing was live — the table does not exist and the plugin is not installed — so all of these were waiting for the first person to use it. ── The second unnamed design could not be saved ── `uniqueIndex(userId, title)`, and every design starts life called "Untitled": `titleOf` returns it for a document with no title and the API defaults to it. So the first saved, the second collided, and the insert threw under a panel that could only say "Changes are not being saved." Renaming one design to match another did the same. Two designs may share a name, as files and notes and dashboards do. Nothing looks a design up by title, so uniqueness bought nothing. The index is now ordinary and on the columns the list query actually uses. The lesson from `dashboards.id` that the schema comment cites is that a key must be scoped to its owner. `userId` on the row does that; making the pair unique as well imported the collision it was citing, one account at a time. ── New did not start a new design ── It cleared `?doc=`, and no parameter already means "open what I had last", answered with `/documents/latest`. So New handed back the design on screen and pointed the next save at its id. There is a `new` sentinel now, in its own module because both panels read it and neither owns it. ── Two ways the load effect raced the debounced save ── Changing `?doc=` does not unmount the panel, so the unmount flush never ran for it: an edit made within the debounce and navigated away from was written after `latest.current` had been replaced, which is to say never. And the first save of a new design puts its id in the URL, which lands in the same effect — re-reading the row overwrote in-memory state with the copy the server had just been given, discarding whatever was drawn during the round trip. The effect now flushes what is pending before it reads, and does not re-read a document it already holds. The editor is keyed on a load generation rather than on `row?.id`, which could not express "blank again" and left the previous design on screen with `rowId` cleared underneath it. ── The typecheck ── 354 of the 355 errors were upstream's tree measured against this platform's settings, which it was never written for. `bunx tsgo` is how this repo is kept clean and it could not be clean while this plugin existed. `exclude` does not help: adapter.ts imports the tree back in. So vendor.sh marks each vendored file unchecked in the same deterministic pass that rewrites its imports. Types still resolve; only the errors inside those files are silenced, which is what the adapter already says the seam is for. Whole repo: 0. ── PROVENANCE.md understated what is done to the copy ── It said "the one edit vendor.sh makes" and described the import rewrite. It also runs apply-host.py, which places our own lib/host.ts and wires three export paths. Four files are not upstream and the document whose job is making the copy trustworthy did not say so. It lists all four now. Also: web/host.ts imported a path only correct at its destination, so the file could never typecheck where it is edited — apply-host.py rewrites that line when placing it, and re-marks the placed copy, which it overwrites after vendor.sh has marked it. PUT is no longer full-replace: omitting `title` renamed a design to "Untitled" and omitting `ui` nulled it, a trap set for the second caller. And a document is bounded at 4 MB, measured in bytes, where the title was capped at 200 and the document at nothing.
This commit is contained in:
+16
-1
@@ -222,7 +222,22 @@ def main() -> int:
|
||||
source = VENDOR.parent / "host.ts"
|
||||
if not source.exists():
|
||||
raise SystemExit("web/host.ts is missing — it is the source for the vendored lib/host.ts.")
|
||||
(VENDOR / "lib" / "host.ts").write_text(source.read_text(encoding="utf-8"), encoding="utf-8")
|
||||
# One line is rewritten on the way in. `web/host.ts` is edited where it lives, so it imports
|
||||
# `./vendor/lib/tokens` — which is correct there and wrong once placed a directory deeper.
|
||||
# Deterministic, like vendor.sh own import rewrite, and it keeps the canonical copy typecheckable
|
||||
# instead of permanently carrying an unresolvable import for the sake of its destination.
|
||||
placed = source.read_text(encoding="utf-8").replace('"./vendor/lib/tokens"', '"./tokens"')
|
||||
if '"./tokens"' not in placed:
|
||||
fail("the tokens import to rewrite", "web/host.ts")
|
||||
|
||||
# Marked like the rest of the vendored tree, because this step runs AFTER vendor.sh has marked it
|
||||
# and writes the file whole — so without this line the mark is lost on every re-vendor and this one
|
||||
# file starts failing the typecheck again. The canonical copy at web/host.ts stays checked; only
|
||||
# the placed copy is exempt, for the same reason its neighbours are.
|
||||
if not placed.startswith("// @ts-nocheck"):
|
||||
placed = "// @ts-nocheck — vendored, see PROVENANCE.md\n" + placed
|
||||
|
||||
(VENDOR / "lib" / "host.ts").write_text(placed, encoding="utf-8")
|
||||
print(" placed lib/host.ts (ours)")
|
||||
for rel, fn in (
|
||||
("Canvas.tsx", canvas),
|
||||
|
||||
+47
-7
@@ -15,8 +15,11 @@
|
||||
# which is what keeps the copy reviewable: `git diff` after a re-vendor shows upstream's real changes,
|
||||
# because the rewrite produces the same output for the same input every time.
|
||||
#
|
||||
# Nothing else is edited. Officer's own changes live outside `web/vendor/`, reached through
|
||||
# `web/adapter.ts`.
|
||||
# The other edit is `apply-host.py`, run at the end: it places our own `lib/host.ts` and wires the host
|
||||
# hooks into the three export paths. Nothing else is touched, and PROVENANCE.md lists all four files so
|
||||
# somebody diffing against upstream can account for every difference.
|
||||
#
|
||||
# Officer's own code lives outside `web/vendor/`, reached through `web/adapter.ts`.
|
||||
set -euo pipefail
|
||||
|
||||
REF="${1:-main}"
|
||||
@@ -61,8 +64,27 @@ find "$DEST" \( -name '*.test.ts' -o -name '*.test.tsx' -o -name '*.spec.ts' -o
|
||||
# ── the mechanical rewrite ──
|
||||
# `@/lib/x` -> relative path to vendor/lib/x
|
||||
# `@/components/x` -> relative path to vendor/components/x
|
||||
# and `// @ts-nocheck` at the top of every file — see the long note below.
|
||||
python3 - "$DEST" <<'PY'
|
||||
import os, re, sys
|
||||
|
||||
# Upstream is a Next.js app and is typechecked as one. This platform is stricter — verbatimModuleSyntax,
|
||||
# strictNullChecks, noImplicitAny — and against those settings upstream's tree reports 354 errors it was
|
||||
# never written to satisfy: type-only imports, possibly-null, implicit any.
|
||||
#
|
||||
# That is not a bug in upstream and it is not ours to fix. It is a bug in what it does to everyone else:
|
||||
# `bunx tsgo` is how this repo is kept clean, and it cannot be clean while these files are in it, so the
|
||||
# check stops being a gate and becomes a thing people filter.
|
||||
#
|
||||
# `exclude` in tsconfig does not work here. It drops files from the initial set, but `web/adapter.ts`
|
||||
# imports the tree and TypeScript pulls every one of them back in.
|
||||
#
|
||||
# So each file is marked unchecked, in this same deterministic pass. Types still RESOLVE — the adapter
|
||||
# goes on getting `Doc`, `Frame`, `buildPrompt` and their real signatures — only the errors inside these
|
||||
# files are silenced. That matches what adapter.ts already says the seam is for: when upstream renames
|
||||
# something, the breakage surfaces at the adapter, which is ours and is checked.
|
||||
MARK = "// @ts-nocheck — vendored, see PROVENANCE.md\n"
|
||||
|
||||
dest = sys.argv[1]
|
||||
for root, _, files in os.walk(dest):
|
||||
for name in files:
|
||||
@@ -73,6 +95,10 @@ for root, _, files in os.walk(dest):
|
||||
prefix = "./" if depth == "." else "../" * len(depth.split(os.sep))
|
||||
src = open(path, encoding="utf-8").read()
|
||||
out = re.sub(r'(["\'])@/(lib|components)/', lambda m: f"{m.group(1)}{prefix}{m.group(2)}/", src)
|
||||
# First line, before any "use client" — a directive only has to precede STATEMENTS, and
|
||||
# @ts-nocheck only counts if it is in the file's opening comment block.
|
||||
if not out.startswith("// @ts-nocheck"):
|
||||
out = MARK + out
|
||||
if out != src:
|
||||
open(path, "w", encoding="utf-8").write(out)
|
||||
PY
|
||||
@@ -109,13 +135,27 @@ keep model-provider API keys in \`localStorage\`, which is not how anything here
|
||||
faithful copy carrying an unused module beats a doctored one that cannot be re-vendored. They are
|
||||
inert without a key, and the shell does not surface them.
|
||||
|
||||
## The one edit \`vendor.sh\` makes
|
||||
## What is NOT upstream in this directory
|
||||
|
||||
Every \`@/lib/…\` and \`@/components/…\` import is rewritten to a relative path. This platform already
|
||||
binds \`@/*\` to \`src/apps/officer-web\` and \`@/components/*\` to its own shared components, so an
|
||||
unrewritten import resolves to the WRONG module rather than failing — silent breakage.
|
||||
Four files differ from the clone, and this list is the whole of it. Anything else that does not
|
||||
match upstream is a mistake.
|
||||
|
||||
The rewrite is deterministic, so a re-vendor produces a readable diff of upstream's real changes.
|
||||
**Every \`.ts\`/\`.tsx\` file — the import rewrite.** Every \`@/lib/…\` and \`@/components/…\` import
|
||||
becomes a relative path. This platform already binds \`@/*\` to \`src/apps/officer-web\` and
|
||||
\`@/components/*\` to its own shared components, so an unrewritten import resolves to the WRONG
|
||||
module rather than failing — silent breakage.
|
||||
|
||||
**\`lib/host.ts\` — ours, not upstream's.** Upstream reviewed the host-adapter contract on
|
||||
lnkiai/m3e-canvas#56 and declined to carry it for now, so it is written here and placed by
|
||||
\`scripts/apply-host.py\`. The canonical copy is \`web/host.ts\`; this one is a copy of it.
|
||||
|
||||
**\`Canvas.tsx\`, \`components/PromptPanel.tsx\`, \`components/Inspector.tsx\` — host hooks wired in.**
|
||||
\`apply-host.py\` matches on structure rather than context so upstream can reformat freely, and it
|
||||
stops loudly when an anchor genuinely disappears. All three export paths are wired, which is what
|
||||
upstream said a complete version needs.
|
||||
|
||||
Both transformations are deterministic, so a re-vendor produces a readable diff of upstream's real
|
||||
changes rather than of the edits above.
|
||||
PROV
|
||||
|
||||
echo "vendored $SHA ($WHEN) -> web/vendor/"
|
||||
|
||||
Reference in New Issue
Block a user