Skip to content

Glob-based copy helpers for seeding the workspace from fixtures #6

Description

@devzeebo

Summary

Add helper(s) to copy files into this.workspace from globs resolved relative to the current spec file, preserving (or optionally stripping) path structure. This replaces one-off writeFile seeding when a test needs a realistic fixture tree.

Desired API

given: {
  tests_are_in_workspace,
}

async function tests_are_in_workspace(this: Context) {
  await copy_to_workspace(this.workspace, ["fixtures/**/*.spec.ts"]);
}

Globs are resolved from the directory of the calling spec (the folder that contains the current *.spec.ts), so a layout like:

my-feature.spec.ts
fixtures/
  suite-a/
    foo.spec.ts
  suite-b/
    nested/
      bar.spec.ts

copies those files into the temp workspace while preserving relative paths under that source root.

Base-path stripping

Support an optional base-path pattern so consumers can drop leading segments when placing files in the workspace. Example: base "fixtures/*" removes the first two path segments when they match fixtures/<anything>:

Source (relative to spec dir) Destination in workspace
fixtures/suite-a/foo.spec.ts foo.spec.ts
fixtures/suite-b/nested/bar.spec.ts nested/bar.spec.ts

Without a base path, preserve the full relative path from the spec directory (including fixtures/...).

Sketch (exact signature TBD):

await copy_to_workspace(this.workspace, ["fixtures/**/*.spec.ts"], {
  base: "fixtures/*",
});

Acceptance criteria

  • Export a copy_to_workspace(workspace, globs, options?) helper from agent-gwt
  • Globs are resolved relative to the current test file’s directory (not process.cwd() / package root)
  • Matched files are copied into workspace, creating parent dirs as needed
  • Folder structure under the copy root is preserved by default
  • Optional base pattern strips a matching path prefix (e.g. fixtures/* → drop fixtures/<segment>/) before writing into the workspace
  • Non-matching base does not silently corrupt paths (document / error behavior)
  • Document usage in the README next to the seeded-workspace example
  • Unit tests covering: preserve structure, strip base, multiple globs, nested dirs, no matches

Notes

  • Today seeding is manual (writeFile in given steps); this is the structured alternative for fixture trees.
  • Prefer small, composable helpers over a heavy fixture framework.
  • Implementation will need a reliable “directory of the current spec” signal under vitest (e.g. import.meta.dirname at the call site, or a helper that accepts an explicit from / uses vitest’s test-file path). Decide in implementation which approach is least surprising and document it.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions