Skip to content

Commit d776a6f

Browse files
committed
Fix the deno permissions for tests
1 parent 513507b commit d776a6f

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"pkgx": "deno^1.33.3 npm",
1414
"tasks": {
15-
"test": "deno test --parallel --unstable -A",
15+
"test": "deno test --parallel --unstable --allow-env --allow-read --allow-net=dist.pkgx.dev,github.com,codeload.github.com --allow-write --allow-run=tar,uname,/bin/sh,foo,'C:\\Windows\\system32\\cmd.exe'",
1616
"typecheck": "deno check --unstable ./mod.ts",
1717
"dnt": ".github/deno-to-node.ts"
1818
},

src/hooks/useConfig.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,26 @@ export interface Config {
1919
git?: Path
2020
}
2121

22-
function platform_cache_default(home: Path) {
22+
function platform_cache_default(home: Path, { LOCALAPPDATA }: { LOCALAPPDATA?: string }) {
2323
switch (Deno.build.os) {
2424
case 'darwin':
2525
return home.join('Library/Caches')
2626
case 'windows':
27-
return flatmap(Deno.env.get("LOCALAPPDATA"), Path.abs) ?? home.join('AppData/Local')
27+
return flatmap(LOCALAPPDATA, Path.abs) ?? home.join('AppData/Local')
2828
default:
2929
return home.join('.cache')
3030
}
3131
}
3232

33-
function platform_data_home_default(home: Path) {
33+
function platform_data_home_default(home: Path, { LOCALAPPDATA }: { LOCALAPPDATA?: string }) {
3434
switch (host().platform) {
3535
case 'darwin':
3636
return home.join("Library/Application Support")
3737
case 'windows': {
38-
const LOCALAPPDATA = Deno.env.get('LOCALAPPDATA')
3938
if (LOCALAPPDATA) {
40-
return new Path(LOCALAPPDATA).join("pkgx")
39+
return new Path(LOCALAPPDATA)
4140
} else {
42-
return home.join("AppData/Local/pkgx")
41+
return home.join("AppData/Local")
4342
}}
4443
default:
4544
return home.join(".local/share")
@@ -52,8 +51,8 @@ export function ConfigDefault(env = Deno.env.toObject()): Config {
5251
const home = flatmap(env['PKGX_HOME'], x => new Path(x)) ?? Path.home()
5352
const prefix = flatmap(env['PKGX_DIR']?.trim(), x => new Path(x)) ?? home.join('.pkgx')
5453
const pantries = env['PKGX_PANTRY_PATH']?.split(SEP).compact(x => flatmap(x.trim(), x => Path.abs(x) ?? Path.cwd().join(x))) ?? []
55-
const cache = (flatmap(env["XDG_CACHE_HOME"], Path.abs) ?? platform_cache_default(home)).join("pkgx")
56-
const data = (flatmap(env["XDG_DATA_HOME"], Path.abs) ?? platform_data_home_default(home)).join("pkgx")
54+
const cache = (flatmap(env["XDG_CACHE_HOME"], Path.abs) ?? platform_cache_default(home, env)).join("pkgx")
55+
const data = (flatmap(env["XDG_DATA_HOME"], Path.abs) ?? platform_data_home_default(home, env)).join("pkgx")
5756
const isCI = boolize(env['CI']) ?? false
5857
const UserAgent = flatmap(getv(), v => `libpkgx/${v}`) ?? 'libpkgx'
5958
//TODO prefer 'xz' on Linux (as well) if supported

src/hooks/useTestConfig.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ export function useBaseTestConfig(env?: Record<string, string>) {
66
env ??= {}
77

88
/// always prefer a new prefix
9-
env.HOME ??= Path.mktemp().string
10-
env.PKGX_DIR ??= Path.mktemp().string
11-
env.XDG_DATA_HOME ??= Path.mktemp().string
12-
env.XDG_CACHE_HOME ??= Path.mktemp().string
9+
env.PKGX_HOME ??= Path.mktemp().string
1310

1411
const config = ConfigDefault(env)
1512
if ('UserAgent' in env) {

src/plumbing/resolve.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import SemVer from "../utils/semver.ts"
1111
import Path from "../utils/Path.ts"
1212

1313
Deno.test("resolve cellar.has", {
14-
permissions: {'read': true, 'env': ["TMPDIR", "TMP", "TEMP", "HOME"], 'write': [Deno.env.get("TMPDIR") || Deno.env.get("TMP") || Deno.env.get("TEMP") || "/tmp"] }
14+
permissions: {'read': true, 'env': ["TMPDIR", "TMP", "TEMP"], 'write': [Deno.env.get("TMPDIR") || Deno.env.get("TMP") || Deno.env.get("TEMP") || "/tmp"] }
1515
}, async runner => {
1616
const prefix = useTestConfig().prefix
1717
const pkg = { project: "foo", version: new SemVer("1.0.0") }

0 commit comments

Comments
 (0)