Skip to content

add integration test for (bug?) nested includes with relative hrefs - #5381

Open
gobengo wants to merge 1 commit into
speced:mainfrom
gobengo:test-nested-includes
Open

add integration test for (bug?) nested includes with relative hrefs#5381
gobengo wants to merge 1 commit into
speced:mainfrom
gobengo:test-nested-includes

Conversation

@gobengo

@gobengo gobengo commented Aug 6, 2026

Copy link
Copy Markdown

Motivation:

  • add a test asserting behavior of how nested data-include relative hyperlink references are resolved by respec into the actually-fetched URL

Background:

  • I used data-include="includes/section.md" to include a file that itself had data-include="example.json", thinking this would lead to includes/example.json included in my respec document. I was surprised to find my document rendering a 404 error instead, because respec fetched example.json not includes/example.json.
  • respec docs for data-include say "Paths are relative to the including document", but this isn't clear for document A that includes a document B that includes a document C. When document B includes document C, is 'the including document' doc B or A?
    • Currently the behavior is untested, but things behave like 'the including document' always means the outer-most including document. The current behavior seems like it may have been a bug/oversight.
    • It seems like data-include docs may have been written with the behavior I suspected in mind (paths in nested includes should be resolved relative to the document that includes them, not the top-most include), even if the current implementation behaves differently.
    • I strongly recommend behavior different than the status quo, because that way respec can include documents that themselves include via relative path. That will make it so a file (with nested includes) can be included in more than one respec document, and without having to know about the path of the file that includes it.

Questions

  • Is the current behavior a bug or not?
    • If the current behavior is not matching what the docs intended by "Paths are relative to the including document", then I should update this PR so the test asserts not the current behavior, but the intended behavior. If that's appropriate, say so, and I will update the test and make it pass, so that it works like I wanted, and we can consider it a bug fix in the changeling.

Changes

  • Adds an integration test for nested data-include includes where the included hrefs are relative URIs. Previously, the only test for nested includes used data URIs, which means there is no test asserting behavior of how nested includes build absolute URLs from the relative hrefs.
  • Testers can set SPEC_FILE_PATTERN to override the default pattern used by integration tests. This can be used to speed up test runs by only scanning a subset of test file patterns, e.g. SPEC_FILE_PATTERN='tests/spec/core/data-include-spec.js' pnpm test:integration

Copilot AI lite review requested due to automatic review settings August 6, 2026 21:12
// outer.html (the top-level document), *not* relative to foo/bar.html
// (the file that declared it) — even though foo/bar.html was itself
// fetched from a "foo/" subdirectory.
expect(innerTarget.textContent).toContain(

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

If the current behavior is a bug, then I should make this assertion a not and remove the not from the nest assertion.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a regression test + fixtures to lock down how nested data-include URLs are resolved, and makes Karma spec selection configurable via an environment variable.

Changes:

  • Allow overriding the Karma spec glob with SPEC_FILE_PATTERN.
  • Add nested-include HTML/JSON fixtures to reproduce a nested data-include chain.
  • Add a new spec asserting nested include URL resolution behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/spec/karma.conf.cjs Adds env-var override for selecting which spec files Karma loads
tests/spec/core/nested-include/outer.html Introduces outer fixture doc that triggers the first include
tests/spec/core/nested-include/foo/bar.html Adds included HTML that triggers a nested include
tests/spec/core/nested-include/includes/data.json Adds “top-level resolved” JSON fixture for nested include
tests/spec/core/nested-include/foo/includes/data.json Adds “included-file resolved” JSON fixture for nested include
tests/spec/core/data-include-spec.js Adds a test asserting nested include resolution behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

).toBeTrue();
});

it("resolves a nested data-include's relative URL against the top-level document, not the including file's own URL", async () => {
Comment on lines +161 to +171
// Current behavior: the nested data-include is resolved relative to
// outer.html (the top-level document), *not* relative to foo/bar.html
// (the file that declared it) — even though foo/bar.html was itself
// fetched from a "foo/" subdirectory.
expect(innerTarget.textContent).toContain(
"top-level document (outer.html)"
);
expect(innerTarget.textContent).not.toContain(
"included file's own directory"
);
});
Comment on lines +3 to +9
This nested include uses a URL relative to "includes/data.json". The
question this fixture answers: is that URL resolved relative to *this*
file's location (tests/spec/core/nested-include/foo/bar.html), which
would yield tests/spec/core/nested-include/foo/includes/data.json, or
relative to the top-level document that started the include chain
(tests/spec/core/nested-include/outer.html), which would yield
tests/spec/core/nested-include/includes/data.json?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

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