Skip to content

Commit a64dbff

Browse files
committed
address feedback
1 parent ece14b0 commit a64dbff

3 files changed

Lines changed: 26 additions & 13 deletions

File tree

src/common/inlineScriptCacheKey.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function normalizeExtras(inner: string): string {
3131
return deduped.length > 0 ? `[${deduped.join(',')}]` : '';
3232
}
3333

34+
/** ` >= 2 ; python_version < "3.13"` becomes `>=2 ; python_version<"3.13"`. */
3435
function normalizeRequirementTail(value: string): string {
3536
let result = '';
3637
let unquoted = '';

src/common/inlineScriptCacheLayout.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ function isDescendantPath(rootPath: string, candidatePath: string): boolean {
284284
);
285285
}
286286

287+
function isNonEmptyTrimmedString(value: unknown): value is string {
288+
return typeof value === 'string' && value.length > 0 && value.trim() === value;
289+
}
290+
287291
function validateMeta(value: unknown): InlineScriptEnvMeta | undefined {
288292
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
289293
return undefined;
@@ -292,19 +296,10 @@ function validateMeta(value: unknown): InlineScriptEnvMeta | undefined {
292296
if (obj.schemaVersion !== META_SCHEMA_VERSION) {
293297
return undefined;
294298
}
295-
if (
296-
typeof obj.baseInterpreterPath !== 'string' ||
297-
obj.baseInterpreterPath.length === 0 ||
298-
obj.baseInterpreterPath.trim() !== obj.baseInterpreterPath ||
299-
!path.isAbsolute(obj.baseInterpreterPath)
300-
) {
299+
if (!isNonEmptyTrimmedString(obj.baseInterpreterPath) || !path.isAbsolute(obj.baseInterpreterPath)) {
301300
return undefined;
302301
}
303-
if (
304-
typeof obj.baseInterpreterVersion !== 'string' ||
305-
obj.baseInterpreterVersion.trim().length === 0 ||
306-
obj.baseInterpreterVersion.trim() !== obj.baseInterpreterVersion
307-
) {
302+
if (!isNonEmptyTrimmedString(obj.baseInterpreterVersion)) {
308303
return undefined;
309304
}
310305
if (!isCanonicalIsoTimestamp(obj.lastUsedAt)) {

src/test/common/inlineScriptCacheLayout.unit.test.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,13 @@ suite('inlineScriptCacheLayout', () => {
471471
assert.strictEqual(await resolveCacheEntryPath(cacheRoot, externalEnv), undefined);
472472
});
473473

474+
test('rejects a nested descendant of the cache root', async () => {
475+
const nestedEnv = Uri.joinPath(cacheRoot, 'nested', '0123456789abcdef');
476+
await fs.ensureDir(nestedEnv.fsPath);
477+
478+
assert.strictEqual(await resolveCacheEntryPath(cacheRoot, nestedEnv), undefined);
479+
});
480+
474481
test('surfaces a missing entry', async () => {
475482
await assert.rejects(
476483
resolveCacheEntryPath(cacheRoot, Uri.joinPath(cacheRoot, '0123456789abcdef')),
@@ -519,13 +526,23 @@ suite('inlineScriptCacheLayout', () => {
519526
assert.strictEqual(await inspectOwnedCacheEntry(otherManager, cacheRoot, envDir), 'uncertain');
520527
});
521528

522-
test('classifies an inline environment resolving elsewhere as stale', async () => {
529+
test('classifies an inline environment with a mismatched sysPrefix as stale', async () => {
530+
const externalPrefix = path.join(tmpDir, 'external-env');
531+
await fs.ensureDir(externalPrefix);
532+
const mismatched = {
533+
...environment,
534+
sysPrefix: externalPrefix,
535+
};
536+
537+
assert.strictEqual(await inspectOwnedCacheEntry(mismatched, cacheRoot, envDir), 'stale');
538+
});
539+
540+
test('classifies an inline environment with a mismatched environmentPath as stale', async () => {
523541
const externalPrefix = path.join(tmpDir, 'external-env');
524542
const externalPython = getVenvPythonPath(externalPrefix);
525543
await fs.outputFile(externalPython, '');
526544
const mismatched = {
527545
...environment,
528-
sysPrefix: externalPrefix,
529546
environmentPath: Uri.file(externalPython),
530547
};
531548

0 commit comments

Comments
 (0)