From e21e04d1f3183d581e0a47461af003b93bba7166 Mon Sep 17 00:00:00 2001 From: Stella Huang Date: Fri, 8 May 2026 13:51:01 -0700 Subject: [PATCH] change script name --- .../templates/new723ScriptTemplate/script.py | 2 +- .../creators/newScriptProject.unit.test.ts | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/test/features/creators/newScriptProject.unit.test.ts diff --git a/files/templates/new723ScriptTemplate/script.py b/files/templates/new723ScriptTemplate/script.py index 1c57fc67..7511eea1 100644 --- a/files/templates/new723ScriptTemplate/script.py +++ b/files/templates/new723ScriptTemplate/script.py @@ -1,4 +1,4 @@ -# /// script_name +# /// script # requires-python = ">=X.XX" TODO: Update this to the minimum Python version you want to support # dependencies = [ # TODO: Add any dependencies your script requires diff --git a/src/test/features/creators/newScriptProject.unit.test.ts b/src/test/features/creators/newScriptProject.unit.test.ts new file mode 100644 index 00000000..897544f3 --- /dev/null +++ b/src/test/features/creators/newScriptProject.unit.test.ts @@ -0,0 +1,44 @@ +import assert from 'assert'; +import * as fs from 'fs-extra'; +import * as os from 'os'; +import * as path from 'path'; + +// Path to the real script template, resolved from the compiled test location +// (out/test/features/creators/ → workspaceRoot/files/templates/...). We do NOT +// rely on `NEW_PROJECT_TEMPLATES_FOLDER` because it is anchored at +// `path.dirname(__dirname)` of the compiled `constants.js`, which resolves to +// `out/` in test mode and does not contain the bundled template tree. +const TEMPLATE_PATH = path.join( + __dirname, + '..', + '..', + '..', + '..', + 'files', + 'templates', + 'new723ScriptTemplate', + 'script.py', +); + +suite('new723ScriptTemplate / NewScriptProject', () => { + let tmpDir: string; + + setup(async () => { + tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'new-script-test-')); + }); + + teardown(async () => { + await fs.remove(tmpDir); + }); + + test('Template file starts with a valid PEP 723 header (# /// script)', async () => { + const contents = await fs.readFile(TEMPLATE_PATH, 'utf8'); + const firstNonBlankLine = contents.split(/\r?\n/).find((l) => l.trim().length > 0); + + assert.strictEqual( + firstNonBlankLine, + '# /// script', + 'Template must start with a valid PEP 723 `script` header line', + ); + }); +});