refactor(portability): migrate to git-source; delete github-fetch.ts #15

Merged
cpfarhood merged 2 commits from feat/portability-git-backend-agnostic into dev 2026-05-16 14:43:35 +00:00
cpfarhood commented 2026-05-16 14:28:42 +00:00 (Migrated from github.com)

Summary

Mirrors PR #13 for the second user of the per-host REST shim. `company-portability.ts` had its own parallel `parseGitHubSourceUrl` + fetch helpers + raw.githubusercontent URL builder, so importing a company package from a non-github URL hit the same Gitea 404 the skills path did. This routes portability through `git-source.ts` and deletes the legacy module.

What changed

  • `git-source.ts` extensions:
    • `parseGitSourceUrl` now recognises the query-string shape (`?ref=...&path=...`) used by portability URLs, with precedence over path-style segments when both are present.
    • `RepoSnapshot` adds `readBinary` (`Uint8Array`, for the company-logo fetch) and `readFileOptional` (returns `null` on `NotFoundError`, for the `COMPANY.md` probe + main→master fallback).
  • `company-portability.ts`: `resolveSource` now opens a single in-memory snapshot per import and serves all reads (`COMPANY.md`, candidate tree, includes, logo) from it. Drops `fetchText`/`fetchJson`/`fetchBinary`/`fetchOptionalText`.
  • Public API preserved: `parseGitHubSourceUrl` stays exported with its original return shape (`{hostname, owner, repo, ref, basePath, companyPath}`) so the existing test suite passes unchanged. It now delegates URL parsing to `parseGitSourceUrl` and layers `companyPath` derivation on top.
  • Deleted: `server/src/services/github-fetch.ts` — zero remaining callers.

Test plan

  • 7 new `git-source.ts` tests (query-string parse variants + precedence, `readBinary`, `readFileOptional` null + rethrow). 34/34 passing.
  • 52 existing `company-portability.test.ts` tests pass via the `parseGitHubSourceUrl` shim.
  • Smoke-tested end-to-end against `https://git.farh.net/...?ref=main`: ref resolves, snapshot opens, `readFile`/`readBinary`/`readFileOptional` all return expected results.
  • `pnpm --filter @paperclipai/server typecheck` clean.
  • Manual: import a public company package from Gitea/Forgejo.
  • Manual: import a company package from a private github repo with a PAT.
  • Manual: regression-test importing a github company that uses the `?ref=&path=` URL shape.

Two pre-existing failures in `company-skills-routes.test.ts` exist on `dev` too and are unrelated to this change.

🤖 Generated with Claude Code

## Summary Mirrors PR #13 for the second user of the per-host REST shim. \`company-portability.ts\` had its own parallel \`parseGitHubSourceUrl\` + fetch helpers + raw.githubusercontent URL builder, so importing a company package from a non-github URL hit the same Gitea 404 the skills path did. This routes portability through \`git-source.ts\` and deletes the legacy module. ## What changed - **\`git-source.ts\` extensions:** - \`parseGitSourceUrl\` now recognises the query-string shape (\`?ref=...&path=...\`) used by portability URLs, with precedence over path-style segments when both are present. - \`RepoSnapshot\` adds \`readBinary\` (\`Uint8Array\`, for the company-logo fetch) and \`readFileOptional\` (returns \`null\` on \`NotFoundError\`, for the \`COMPANY.md\` probe + main→master fallback). - **\`company-portability.ts\`:** \`resolveSource\` now opens a single in-memory snapshot per import and serves all reads (\`COMPANY.md\`, candidate tree, includes, logo) from it. Drops \`fetchText\`/\`fetchJson\`/\`fetchBinary\`/\`fetchOptionalText\`. - **Public API preserved:** \`parseGitHubSourceUrl\` stays exported with its original return shape (\`{hostname, owner, repo, ref, basePath, companyPath}\`) so the existing test suite passes unchanged. It now delegates URL parsing to \`parseGitSourceUrl\` and layers \`companyPath\` derivation on top. - **Deleted:** \`server/src/services/github-fetch.ts\` — zero remaining callers. ## Test plan - [x] 7 new \`git-source.ts\` tests (query-string parse variants + precedence, \`readBinary\`, \`readFileOptional\` null + rethrow). 34/34 passing. - [x] 52 existing \`company-portability.test.ts\` tests pass via the \`parseGitHubSourceUrl\` shim. - [x] Smoke-tested end-to-end against \`https://git.farh.net/...?ref=main\`: ref resolves, snapshot opens, \`readFile\`/\`readBinary\`/\`readFileOptional\` all return expected results. - [x] \`pnpm --filter @paperclipai/server typecheck\` clean. - [ ] Manual: import a public company package from Gitea/Forgejo. - [ ] Manual: import a company package from a private github repo with a PAT. - [ ] Manual: regression-test importing a github company that uses the \`?ref=&path=\` URL shape. > Two pre-existing failures in \`company-skills-routes.test.ts\` exist on \`dev\` too and are unrelated to this change. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.