Skip to content

test: template pack edge cases#3497

Open
fredericoo wants to merge 2 commits intomainfrom
fb-test-pack-sad-path
Open

test: template pack edge cases#3497
fredericoo wants to merge 2 commits intomainfrom
fb-test-pack-sad-path

Conversation

@fredericoo
Copy link
Contributor

@fredericoo fredericoo commented Feb 24, 2026

WHY are these changes introduced?

replaceWorkspaceProtocolVersions runs in the template packaging path used for releases. The existing integration coverage verified that workspace: and catalog: prefixes were removed, but it did not verify exact catalog: resolution or the error behavior when protocol-based dependencies cannot be found in the packed manifest.

WHAT is this pull request doing?

  • Adds a helper in template-pack.test.ts to read a dependency version from the catalog section of pnpm-workspace.yaml.
  • Strengthens the existing integration test to assert the exact resolved value for react (from catalog) instead of only checking protocol prefix removal.
  • Adds a test that asserts a clear error is thrown when a workspace:* dependency is missing from the packed manifest.
  • Adds a test that asserts a clear error is thrown when a catalog: dependency is missing from the packed manifest.

HOW to test your changes?

  1. Run cd packages/cli
  2. Run pnpm exec vitest run src/lib/template-pack.test.ts
  3. Confirm all tests pass (currently 3 tests in this file)

Post-merge steps

None.

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

@shopify
Copy link
Contributor

shopify bot commented Feb 24, 2026

Oxygen deployed a preview of your fb-test-pack-sad-path branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment February 24, 202612:25 PM

Learn more about Hydrogen's GitHub integration.

function getCatalogVersion(sourceTemplateDir: string, packageName: string) {
const catalogVersion = execFileSync(
'pnpm',
['config', 'get', `catalog.${packageName}`, '--location', 'project'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL you can do this to get configs from pnpm and it will be monorepo aware but scoped to the right project, really cool

i was trying to do this with regexes reading the yaml, considered a yaml parser but this is even better

@fredericoo fredericoo marked this pull request as ready for review February 24, 2026 12:25
@fredericoo fredericoo requested a review from a team as a code owner February 24, 2026 12:25
@github-actions
Copy link
Contributor

We detected some changes in packages/*/package.json or packages/*/src, and there are no updates in the .changeset.
If the changes are user-facing and should cause a version bump, run pnpm run changeset add to track your changes and include them in the next release CHANGELOG.
If you are making simple updates to examples or documentation, you do not need to add a changeset.

}
}

expect(copiedPackageJson.dependencies?.react).toBe(expectedReactVersion);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the happy-path test should also positively assert a workspace:* resolved version.

The new react assertion is a great addition - it positively verifies the resolved value for a catalog: dependency. But the workspace:* dependencies (like @shopify/mini-oxygen in devDependencies) are only checked with negative assertions ("no workspace: prefix remains"). If the function resolved a workspace:* dep to an unexpected value, the negative assertion would still pass.

I think adding one positive spot-check would close this gap:

Suggested change
expect(copiedPackageJson.dependencies?.react).toBe(expectedReactVersion);
expect(copiedPackageJson.dependencies?.react).toBe(expectedReactVersion);
expect(copiedPackageJson.devDependencies?.['@shopify/mini-oxygen']).toMatch(
/^\d+\.\d+\.\d+/,
);

non-blocking (but in a "we definitely should do this, but i'm okay if you want to do it as a follow up PR" way)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sounds sensible yeah

});
});

it('throws a clear error when a workspace dependency is missing from the packed manifest', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the two error-path tests share ~18 lines of identical scaffolding (copy skeleton, read JSON, inject fake dep, write, assert rejection). At two instances this is at the boundary - I'm fine with keeping them inline since each test reads top-to-bottom as a self-contained story. But if a third error case is added (e.g., testing devDependencies or peerDependencies), I think extracting a shared helper would be clearly justified.

non-blocking

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed! i also draw the line at 2 hahah

},
).trim();

if (!catalogVersion || catalogVersion === 'undefined') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this === 'undefined' check might look like a bug to a future reader who doesn't know that pnpm config get returns the literal string "undefined" for missing keys. I think a one-line comment would prevent confusion:

Suggested change
if (!catalogVersion || catalogVersion === 'undefined') {
// pnpm config get returns the literal string "undefined" for missing keys
if (!catalogVersion || catalogVersion === 'undefined') {

non-blocking

@@ -52,6 +74,72 @@ describe('replaceWorkspaceProtocolVersions', () => {
expect(version.startsWith('catalog:')).toBe(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(threading) Re: line 52 - I think the comment on the @shopify/hydrogen injection should explain why this specific package was chosen. The choice is load-bearing - it must be a real workspace package that exists in the packed manifest's dependencies section for the test to work.

non-blocking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants