Skip to content

Make standalone script template creation reliable - #1736

Merged
Stella Huang (StellaHuang95) merged 5 commits into
microsoft:mainfrom
StellaHuang95:copilot/pep723-template-creator
Aug 26, 2026
Merged

Make standalone script template creation reliable#1736
Stella Huang (StellaHuang95) merged 5 commits into
microsoft:mainfrom
StellaHuang95:copilot/pep723-template-creator

Conversation

@StellaHuang95

Copy link
Copy Markdown
Contributor

Context

The existing Script project template is presented as a PEP 723 standalone script, but its placeholder metadata is not valid TOML. The quick-create path also returns without creating a file, even though external callers provide a script project name and destination.

This change fixes the existing user-facing template and file-creation workflow. It does not create, select, or expose an inline-script environment.

Why this change is needed

  • The shipped metadata block cannot be parsed by the extension's own PEP 723 parser.
  • Quick create skips the copy/register/open path.
  • External quick callers provide a base project name such as hello_world, not necessarily a complete .py filename.
  • Filename/path handling needs to reject traversal, reserved Windows device names, remote-workspace identity loss, and physical symlink escapes.
  • Project-registration failure can otherwise leave a generated file or in-memory ghost project.
  • Copilot instruction paths can be redirected outside the workspace through existing symlinks or junctions.

What changed

  • The template now contains valid requires-python = ">=3.9" metadata and an empty dependency list.
  • Quick base names are normalized to .py; interactive creation continues requiring an explicit .py filename.
  • Interactive and quick flows share validation for extension, characters, separators, traversal, containment, and Windows reserved names.
  • Workspace matching preserves remote URI scheme and authority.
  • Destination and Copilot-instruction paths are physically checked against the containing workspace before any side effect.
  • Quick and interactive creation share the file copy, substitution, project registration, instruction, and open flow.
  • Project registration is awaited. Insert-then-fail behavior removes the in-memory project and copied script while preserving the original error.
  • Out-of-workspace destinations are rejected because they cannot be durably registered.
  • Related documentation and Copilot instructions now describe the actual script behavior and metadata fields.

Behavior and compatibility

  • Package project creation is unchanged.
  • Script creation still does not provision an environment.
  • The hidden inline manager remains undeclared, default-off, and unregistered.
  • Users already saw a PEP 723 block in generated scripts; this change makes that existing block valid.
  • Opening the now-valid generated file may emit the existing anonymized telemetry-only detection event. It does not create or select an environment.

Reviewer guide

  1. Review shared filename normalization and validation.
  2. Review workspace URI matching and physical containment preflight.
  3. Review side-effect ordering and registration rollback.
  4. Review the actual template parser test and quick-create tests.

Validation

  • npm run compile-tests --silent
  • Targeted metadata parser and script creator suites: 71 passing
  • ESLint on changed TypeScript files
  • git diff --check

@StellaHuang95 Stella Huang (StellaHuang95) added the feature-request Request for new features or functionality label Aug 25, 2026
Comment thread src/features/creators/newScriptProject.ts
Comment thread src/features/creators/newScriptProject.ts
@heejaechang

Copy link
Copy Markdown

GitHub cannot anchor PR review comments to unchanged lines in the diff. Falling back to a general PR comment for src/features/creators/newScriptProject.ts:L336.

Warning · Non-blocking recommendation

After project registration succeeds, failures from Copilot-instruction management or showTextDocument reject create while retaining the generated file and project. Define the registration commit boundary explicitly: either roll back these resources on such failures or make post-registration editor opening best-effort, with focused failure coverage.

Comment thread src/test/features/creators/newScriptProject.unit.test.ts
@heejaechang

Copy link
Copy Markdown

Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approved via Review Center.

Comment thread src/features/creators/newScriptProject.ts Outdated
@heejaechang

Copy link
Copy Markdown

Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified.

@heejaechang Heejae Chang (heejaechang) added review-auto:changes-requested Automated review: posted blocking findings to address. and removed review-auto:approved Automated review: no blocking findings (approval posted). labels Aug 25, 2026
Comment thread src/features/creators/newScriptProject.ts
Comment thread src/features/creators/newScriptProject.ts
Comment thread src/test/features/creators/newScriptProject.unit.test.ts
@heejaechang

Copy link
Copy Markdown

Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified.

1 similar comment
@heejaechang

Copy link
Copy Markdown

Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified.

Comment thread src/features/creators/newScriptProject.ts Outdated
Comment thread src/features/creators/newScriptProject.ts
Comment thread src/features/creators/newScriptProject.ts Outdated
@StellaHuang95
Stella Huang (StellaHuang95) force-pushed the copilot/pep723-template-creator branch from 7b39699 to 0b95ef8 Compare August 26, 2026 18:38
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extract isSameOrParentPath into common/utils/pathUtils and reuse it in
newScriptProject and terminal/utils instead of duplicated local copies.
Remove the niche fs.realpath/symlink containment preflight and
isCopilotInstructionsDestinationContained while keeping input
validation, remote-URI identity, logical workspace containment, and
registration rollback. Update unit tests accordingly.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1487b95c-ac14-455f-9b7f-9770cf65e11e
Resolve the destination and workspace roots with fs.realpath and
reject when the destination physically escapes the workspace (e.g. via
a symlink or junction) before fs.copy. Addresses review feedback that
the previous containment check was lexical only. Adds back a unit test
for the symlink-escape rejection.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1487b95c-ac14-455f-9b7f-9770cf65e11e
Wrap the template copy, name substitution, and project registration in a
single cleanup boundary so a failure after fs.copy removes the partially
created script instead of leaving it behind and blocking a clean retry.
Make the test fixture's pathExists fake resolve by the requested path
rather than by call order, and add a regression test for the
substitution-failure rollback.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1487b95c-ac14-455f-9b7f-9770cf65e11e
Move the Windows reserved-device-name test out of the script filename
validator and into a shared isWindowsReservedDeviceName helper in
common/utils/pathUtils, so the rule lives with the other path utilities
and can be reused. newScriptProject now calls the helper and no longer
imports isWindows directly. Add focused unit coverage for the helper.

Rename the internal template folder new723ScriptTemplate to
newInlineScriptTemplate and update all creator and test references. Only
the folder name changes; the template content and the user-facing
creator, class, and command are untouched.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1487b95c-ac14-455f-9b7f-9770cf65e11e
@StellaHuang95 Stella Huang (StellaHuang95) removed the review-auto:changes-requested Automated review: posted blocking findings to address. label Aug 26, 2026
@StellaHuang95
Stella Huang (StellaHuang95) merged commit 9e44ce1 into microsoft:main Aug 26, 2026
46 checks passed
@StellaHuang95
Stella Huang (StellaHuang95) deleted the copilot/pep723-template-creator branch August 26, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-request Request for new features or functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants