GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — onicode/scripts/upstream-sync.test.ts at main · aislopware/onicode Expand file tree/ Copy pathupstream-sync.test.tsMore file actions 351 lines (336 loc) · 14.5 KB / Copy pathupstream-sync.test.tsFile metadata and controls351 lines (336 loc) · 14.5 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 // @effect-diagnostics nodeBuiltinImport:off import * as NodeChildProcess from "node:child_process"; import * as NodeFS from "node:fs"; import * as NodeOS from "node:os"; import * as NodePath from "node:path"; import { describe, expect, it } from "vite-plus/test"; import { portCommitCommand, riskAreas, translatePath, translateText, writeBlob, } from "./upstream-sync.ts"; describe("upstream-sync translation", () => { it.each([ ['import { x } from "@t3tools/contracts";', 'import { x } from "@onicode/contracts";'], ["process.env.T3CODE_HOME ?? T3_PORT", "process.env.ONICODE_HOME ?? ONICODE_PORT"], ["T3 Code keeps a t3code checkpoint", "Onicode keeps a onicode checkpoint"], ["new T3ConnectClient()", "new T3ConnectClient()"], [ "see https://github.com/pingdotgg/t3code/pull/42, pingdotgg/t3code#7 and https://github.com/pingdotgg/t3code/commit/1bc8e2d", "see https://github.com/pingdotgg/t3code/pull/42, pingdotgg/t3code#7 and https://github.com/pingdotgg/t3code/commit/1bc8e2d", ], [ "https://github.com/PingDotGG/T3Code/pull/42 and pingdotgg/t3code/commit/ABC1234", "https://github.com/PingDotGG/T3Code/pull/42 and pingdotgg/t3code/commit/ABC1234", ], [ "git clone https://github.com/pingdotgg/t3code", "git clone https://github.com/aislopware/onicode", ], [ "https://github.com/pingdotgg/t3code/issues/new?template=bug.yml", "https://github.com/aislopware/onicode/issues/new?template=bug.yml", ], [ "curl -fsSL https://t3.codes/install.sh | sh", "curl -fsSL https://raw.githubusercontent.com/aislopware/onicode/main/scripts/install.sh | sh", ], ["react-native-screens-5.0.0-t3.48.tgz", "react-native-screens-5.0.0-t3.48.tgz"], // A tab escape before a digit is not the t3 brand. ['"Apples green\\t3\\t\\nAfter"', '"Apples green\\t3\\t\\nAfter"'], ['"row\\t3A"', '"row\\t3A"'], // An escaped backslash before it leaves the brand. ['"C:\\\\t3\\\\bin"', '"C:\\\\onicode\\\\bin"'], ['"C:\\\\t3-cli"', '"C:\\\\oni-cli"'], [ "runInNewContext(`${source}\\nt3McpExtension(pi)`)", "runInNewContext(`${source}\\noniMcpExtension(pi)`)", ], [ "PI_T3_MCP_EXTENSION_SOURCE ?? __T3_SETUP_DONE__", "PI_ONI_MCP_EXTENSION_SOURCE ?? __ONI_SETUP_DONE__", ], [ "globalThis.__t3Recorder ?? msg_t3_turn_ ?? _t3/empty", "globalThis.__oniRecorder ?? msg_oni_turn_ ?? _oni/empty", ], ['first_t3="$(command -v t3)"', 'first_onicode="$(command -v onicode)"'], ["mcp__t3_code__delegate_task", "mcp__onicode__delegate_task"], // Onicode has no T3 Chat theme, so its names stay upstream's and a port that uses them fails. [ 'T3_CHAT_THEME.id === "t3-chat" && host === "t3.chat"', 'T3_CHAT_THEME.id === "t3-chat" && host === "t3.chat"', ], ["com.t3tools.t3code.widgets", "dev.aislopware.onicode.widgets"], ["java/com/t3tools/t3code/MainActivity.kt", "java/dev/aislopware/onicode/MainActivity.kt"], ])("%s", (upstream, onicode) => { expect(translateText(upstream)).toBe(onicode); }); it.each([ "packages/shared/src/paletteSearch.test.ts", ".github/scripts/stage-preview-bundle.test.py", ])("translates upstream references in %s with the repository name beside them", (path) => { expect( translateText( 'repository: "pingdotgg/t3code", url: "https://github.com/pingdotgg/t3code/pull/42"', path, ), ).toBe( 'repository: "aislopware/onicode", url: "https://github.com/aislopware/onicode/pull/42"', ); }); it("renames t3 paths the way the rebrand did", () => { expect(translatePath("apps/mobile/modules/t3-terminal/ios/T3TerminalView.swift")).toBe( "apps/mobile/modules/oni-terminal/ios/OniTerminalView.swift", ); expect(translatePath("packages/shared/src/git.ts")).toBe("packages/shared/src/git.ts"); }); }); describe("upstream-sync port commit", () => { it("keeps the upstream author and co-authors on the Onicode commit", () => { const repo = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "upstream-sync-commit-")); try { const git = (...args: ReadonlyArray<string>) => NodeChildProcess.execFileSync("git", args, { cwd: repo, encoding: "utf8" }).trim(); git("init", "-q"); git("config", "user.name", "Onicode Maintainer"); git("config", "commit.gpgsign", "false"); git("config", "core.hooksPath", "/dev/null"); NodeFS.writeFileSync(NodePath.join(repo, "file.txt"), "before\n"); git("add", "file.txt"); git("commit", "-qm", "seed"); NodeFS.writeFileSync(NodePath.join(repo, "file.txt"), "after\n"); NodeChildProcess.execSync( portCommitCommand({ sha: "7e45dcdd61942973b4f026d01ca89b4128d438c8", subject: "fix(web): T3 Code's `$HOME` stays put (#1)", author, }), { cwd: repo, stdio: "ignore" }, ); expect(git("log", "-1", "--format=%an <%ae>|%cn")).toBe(`${author}|Onicode Maintainer`); expect(git("log", "-1", "--format=%B")).toBe( "fix(web): Onicode's `$HOME` stays put (#1)\n\n" + "Ported from pingdotgg/t3code@7e45dcdd61.\n\n" + "Co-authored-by: Claude Opus 5.5 <[email protected]>", ); } finally { NodeFS.rmSync(repo, { recursive: true, force: true }); } }); }); describe("upstream-sync blob writes", () => { it("lands a symlink as a link and keeps an executable's bit", () => { const dir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "upstream-sync-modes-")); try { const link = NodePath.join(dir, "ios", "Engine.swift"); NodeFS.mkdirSync(NodePath.dirname(link), { recursive: true }); NodeFS.writeFileSync(NodePath.join(dir, "target.txt"), "kept\n"); NodeFS.symlinkSync("../target.txt", link); // An existing link is replaced, not written through to its target. writeBlob(link, Buffer.from("../shared/Engine.swift"), "120000"); const script = NodePath.join(dir, "bin", "run.sh"); writeBlob(script, Buffer.from("#!/bin/sh\n"), "100755"); const plain = NodePath.join(dir, "bin", "notes.txt"); writeBlob(plain, Buffer.from("notes\n"), "100644"); expect([ NodeFS.readlinkSync(link), NodeFS.readFileSync(NodePath.join(dir, "target.txt"), "utf8"), NodeFS.statSync(script).mode & 0o111, NodeFS.statSync(plain).mode & 0o111, ]).toEqual(["../shared/Engine.swift", "kept\n", 0o111, 0]); } finally { NodeFS.rmSync(dir, { recursive: true, force: true }); } }); }); describe("upstream-sync port modes", () => { it("ports links and modes whole, and keeps Onicode's side where both changed one", () => { const repo = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "upstream-sync-port-")); try { const at = (path: string) => NodePath.join(repo, path); const git = (...args: ReadonlyArray<string>) => NodeChildProcess.execFileSync("git", args, { cwd: repo, encoding: "utf8" }).trim(); const file = (path: string, data: string | Buffer, mode = 0o644) => { NodeFS.mkdirSync(NodePath.dirname(at(path)), { recursive: true }); NodeFS.rmSync(at(path), { force: true }); NodeFS.writeFileSync(at(path), data); NodeFS.chmodSync(at(path), mode); }; const link = (path: string, target: string) => { NodeFS.mkdirSync(NodePath.dirname(at(path)), { recursive: true }); NodeFS.rmSync(at(path), { force: true }); NodeFS.symlinkSync(target, at(path)); }; const commit = (message: string) => { git("add", "-A", "."); git("commit", "-qm", message); }; git("init", "-q", "-b", "main"); git("config", "user.name", "Onicode Maintainer"); git("config", "commit.gpgsign", "false"); git("config", "core.hooksPath", "/dev/null"); // The exec bit must still reach the index where git ignores the worktree's. git("config", "core.fileMode", "false"); link("both.link", "a.txt"); file("edited.txt", "base\n"); link("moved.link", "nowhere"); file("chmodded.txt", "same\n"); file("image.bin", Buffer.from([0, 1, 2])); file("typed.txt", "plain\n"); file("notes.txt", "one\n"); link("retarget.link", "old.txt"); file("blob.dat", Buffer.from([0, 1])); file("foo*.txt", "glob\n"); file("foo-other.txt", "other\n"); file("relinked.txt", "dest"); commit("base"); git("branch", "upstream"); git("checkout", "-q", "upstream"); link("new.link", "../t3code.txt"); file("run.sh", "#!/bin/sh\n", 0o755); git("add", "run.sh"); git("update-index", "--chmod=+x", "--", "run.sh"); link("both.link", "b.txt"); file("edited.txt", "base\nupstream\n"); git("mv", "moved.link", "renamed.link"); git("rm", "-q", "chmodded.txt"); file("notes.txt", "one\ntwo\n"); link("retarget.link", "same.txt"); file("blob.dat", "upstream text\n"); NodeFS.rmSync(at("foo*.txt")); link("relinked.txt", "dest"); git("add", "-A", "."); git("update-index", "--chmod=+x", "--", "image.bin", "typed.txt"); commit("upstream"); const upstream = git("rev-parse", "HEAD"); git("checkout", "-q", "main"); link("both.link", "c.txt"); link("edited.txt", "elsewhere.txt"); link("typed.txt", "plain.txt"); git("add", "-A", "."); git("update-index", "--chmod=+x", "--", "chmodded.txt"); file("image.bin", Buffer.from([0, 9, 9])); link("retarget.link", "same.txt"); file("blob.dat", "onicode text\n"); file("relinked.txt", "edited"); git("add", "-A", "."); commit("onicode"); file( "scripts/upstream-sync.ts", NodeFS.readFileSync(new URL("./upstream-sync.ts", import.meta.url)), ); const port = () => NodeChildProcess.spawnSync( process.execPath, ["scripts/upstream-sync.ts", "port", upstream], { cwd: repo, encoding: "utf8", }, ); git("config", "core.symlinks", "false"); expect(port().stderr).toContain("upstream's links must land as links"); git("config", "core.symlinks", "true"); const ported = NodeChildProcess.spawnSync( process.execPath, ["scripts/upstream-sync.ts", "port", upstream], { cwd: repo, encoding: "utf8" }, ); expect(ported.stderr).toBe(""); const modes = Object.fromEntries( git("ls-files", "-s") .split("\n") .map((line) => [line.split("\t")[1], line.split(" ")[0]]), ); expect({ newLink: NodeFS.readlinkSync(at("new.link")), newLinkMode: modes["new.link"], script: modes["run.sh"], // Both changed the target: Onicode's link stays, and the port says so. bothLink: NodeFS.readlinkSync(at("both.link")), // Onicode made it a link and upstream edited the file: the link stays. edited: NodeFS.readlinkSync(at("edited.txt")), // Onicode made it a link, upstream made the file executable. typed: NodeFS.readlinkSync(at("typed.txt")), // A dangling link moves too. renamed: NodeFS.readlinkSync(at("renamed.link")), movedGone: NodeFS.lstatSync(at("moved.link"), { throwIfNoEntry: false }), // Upstream deleted a file Onicode only made executable: it stays. chmodded: modes["chmodded.txt"], // Onicode's bytes, with upstream's new exec bit. image: [...NodeFS.readFileSync(at("image.bin"))], imageMode: modes["image.bin"], // Both sides made the same change. retarget: NodeFS.readlinkSync(at("retarget.link")), // A binary base both sides replaced with text: Onicode's text stays. blob: NodeFS.readFileSync(at("blob.dat"), "utf8"), // A path with a glob character deletes that file only. globGone: NodeFS.existsSync(at("foo*.txt")), other: NodeFS.existsSync(at("foo-other.txt")), // Upstream made it a link to its old bytes, Onicode edited the file. relinked: NodeFS.readFileSync(at("relinked.txt"), "utf8"), // Merged content stays unstaged for review; only the bit is staged. unstaged: git("diff", "--name-only").split("\n"), staged: git("diff", "--cached", "--name-only").split("\n"), }).toEqual({ newLink: "../onicode.txt", newLinkMode: "120000", script: "100755", bothLink: "c.txt", edited: "elsewhere.txt", typed: "plain.txt", renamed: "nowhere", movedGone: undefined, chmodded: "100755", image: [0, 9, 9], imageMode: "100755", retarget: "same.txt", blob: "onicode text\n", globGone: false, other: true, relinked: "edited", unstaged: expect.arrayContaining(["notes.txt", "run.sh"]), staged: expect.not.arrayContaining(["notes.txt"]), }); expect(ported.stdout).toContain("CONFLICT blob.dat: binary changed on both sides."); expect(ported.stdout).toContain("CONFLICT both.link: symlink changed on both sides."); expect(ported.stdout).toContain("CONFLICT edited.txt: symlink changed on both sides."); expect(ported.stdout).toContain("CONFLICT relinked.txt: one side made it a symlink"); expect(ported.stdout).toContain( "CONFLICT typed.txt: mode 100644 became 120000 here, 100755", ); expect(ported.stdout).toContain("CONFLICT chmodded.txt: upstream deleted it"); } finally { NodeFS.rmSync(repo, { recursive: true, force: true }); } }); }); describe("upstream-sync risk areas", () => { it.each([ [["apps/server/src/git/GitCore.ts"], 40, []], [ ["packages/contracts/src/orchestration.ts", "apps/mobile/src/App.tsx"], 40, ["contracts", "mobile"], ], [["apps/server/src/persistence/Migrations/082_Example.ts"], 40, ["migrations"]], [["apps/web/src/components/Sidebar.tsx"], 40, ["sidebar"]], [["apps/web/src/components/SidebarRow.tsx"], 40, []], [ ["apps/server/src/desktopUpdate/Service.ts", "apps/server/src/peer/Link.ts"], 40, ["desktop", "auth"], ], [["apps/server/package.json", ".github/workflows/ci.yml"], 40, ["ci", "deps"]], [["apps/web/src/composer.ts"], 401, ["401 lines"]], ])("%j with %i changed lines", (paths, changedLines, expected) => { expect(riskAreas(paths, changedLines)).toEqual(expected); }); }); |
| You are visitor 01402792 — 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. |