@icyouo/evt-cli 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -59,9 +59,13 @@ evt validate
59
59
  ```
60
60
 
61
61
  `evt profile set <name>` stores the default profile in
62
- `data/.evt/config.json` under the active config root. Commands that need a
63
- profile use that value when `--profile` is omitted. Passing `--profile <name>`
64
- still overrides the default for one command.
62
+ `.evt/config.json` under the active config root. Commands that need a profile
63
+ use that value when `--profile` is omitted. Passing `--profile <name>` still
64
+ overrides the default for one command.
65
+
66
+ Runtime state is kept under `.evt/` in the active config root. Session cache and
67
+ live-test reports are written to `.evt/cache/`. The older `.cache/session.local.json`
68
+ path is still read as a compatibility fallback, but new writes use `.evt/cache/`.
65
69
 
66
70
  ## Data Layout
67
71
 
package/README.zh-CN.md CHANGED
@@ -59,9 +59,13 @@ evt validate
59
59
  ```
60
60
 
61
61
  `evt profile set <name>` 会把默认 profile 写到当前 config root 下的
62
- `data/.evt/config.json`。需要 profile 的命令在未传 `--profile` 时会使用这个默认值。
62
+ `.evt/config.json`。需要 profile 的命令在未传 `--profile` 时会使用这个默认值。
63
63
  临时传入 `--profile <name>` 仍然可以覆盖本次命令。
64
64
 
65
+ 运行时状态统一放在当前 config root 下的 `.evt/`。登录 session cache 和真实接口测试
66
+ 报告会写到 `.evt/cache/`。旧的 `.cache/session.local.json` 仍会作为兼容 fallback 读取,
67
+ 但新的写入都会进入 `.evt/cache/`。
68
+
65
69
  ## 数据目录
66
70
 
67
71
  项目数据目录结构:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icyouo/evt-cli",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Run YAML-defined HTTP APIs and interactive workflows from your terminal.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "scripts": {
28
28
  "ci:local": "node scripts/local-ci.js",
29
29
  "test": "node --test",
30
- "check": "node --check bin/evt.js && node --check src/index.js && node --check src/util/settings.js && node --check src/flow/inputResolver.js && node --check src/api/liveTester.js && node --check scripts/sync-api-coverage.js && node --check scripts/check-api-coverage.js && node --check scripts/check-api-audit.js && node --check scripts/local-ci.js && node --check scripts/build-package.js && node --check skills/evt-api-scanner/scripts/discover.js && node --check skills/evt-api-scanner/scripts/scan.js",
30
+ "check": "node --check bin/evt.js && node --check src/index.js && node --check src/util/paths.js && node --check src/util/settings.js && node --check src/cache/sessionCache.js && node --check src/flow/inputResolver.js && node --check src/api/liveTester.js && node --check scripts/sync-api-coverage.js && node --check scripts/check-api-coverage.js && node --check scripts/check-api-audit.js && node --check scripts/local-ci.js && node --check scripts/build-package.js && node --check skills/evt-api-scanner/scripts/discover.js && node --check skills/evt-api-scanner/scripts/scan.js",
31
31
  "package:local": "node scripts/build-package.js",
32
32
  "sync:api": "node scripts/sync-api-coverage.js",
33
33
  "coverage:api": "node scripts/check-api-coverage.js",
@@ -4,7 +4,7 @@ const { buildRequest } = require("../http/requestBuilder");
4
4
  const { readCache } = require("../cache/sessionCache");
5
5
  const { loadFlow } = require("../config/loaders");
6
6
  const { runFlow } = require("../flow/runner");
7
- const { resolveCliPath } = require("../util/paths");
7
+ const { defaultCacheDir } = require("../util/paths");
8
8
  const { redact } = require("../util/redact");
9
9
 
10
10
  function isPlainObject(value) {
@@ -16,7 +16,7 @@ function nowCompact() {
16
16
  }
17
17
 
18
18
  function ensureCacheDir() {
19
- const dir = resolveCliPath(".cache");
19
+ const dir = defaultCacheDir();
20
20
  fs.mkdirSync(dir, { recursive: true });
21
21
  return dir;
22
22
  }
@@ -1,6 +1,6 @@
1
1
  const fs = require("node:fs");
2
2
  const path = require("node:path");
3
- const { defaultCachePath } = require("../util/paths");
3
+ const { defaultCachePath, legacyCachePath } = require("../util/paths");
4
4
 
5
5
  function resolveCachePath(cachePath) {
6
6
  return cachePath ? path.resolve(cachePath) : defaultCachePath();
@@ -8,10 +8,12 @@ function resolveCachePath(cachePath) {
8
8
 
9
9
  function readCache(cachePath) {
10
10
  const file = resolveCachePath(cachePath);
11
- if (!fs.existsSync(file)) {
11
+ const legacyFile = !cachePath ? legacyCachePath() : undefined;
12
+ const readableFile = fs.existsSync(file) ? file : legacyFile;
13
+ if (!readableFile || !fs.existsSync(readableFile)) {
12
14
  return {};
13
15
  }
14
- return JSON.parse(fs.readFileSync(file, "utf8"));
16
+ return JSON.parse(fs.readFileSync(readableFile, "utf8"));
15
17
  }
16
18
 
17
19
  function writeCache(cachePath, value) {
package/src/util/paths.js CHANGED
@@ -25,13 +25,23 @@ function resolveConfigDir(name) {
25
25
  }
26
26
 
27
27
  function defaultCachePath() {
28
+ return resolveCliPath(".evt", "cache", "session.local.json");
29
+ }
30
+
31
+ function legacyCachePath() {
28
32
  return resolveCliPath(".cache", "session.local.json");
29
33
  }
30
34
 
35
+ function defaultCacheDir() {
36
+ return resolveCliPath(".evt", "cache");
37
+ }
38
+
31
39
  module.exports = {
32
40
  cliRoot,
33
41
  configRoot,
42
+ defaultCacheDir,
34
43
  defaultCachePath,
44
+ legacyCachePath,
35
45
  resolveCliPath,
36
46
  resolveConfigDir,
37
47
  setConfigRoot
@@ -3,13 +3,19 @@ const path = require("node:path");
3
3
  const { resolveCliPath } = require("./paths");
4
4
 
5
5
  function settingsPath() {
6
+ return resolveCliPath(".evt", "config.json");
7
+ }
8
+
9
+ function legacySettingsPath() {
6
10
  return resolveCliPath("data", ".evt", "config.json");
7
11
  }
8
12
 
9
13
  function readSettings() {
10
14
  const file = settingsPath();
11
- if (!fs.existsSync(file)) return {};
12
- return JSON.parse(fs.readFileSync(file, "utf8"));
15
+ const legacyFile = legacySettingsPath();
16
+ const readableFile = fs.existsSync(file) ? file : legacyFile;
17
+ if (!fs.existsSync(readableFile)) return {};
18
+ return JSON.parse(fs.readFileSync(readableFile, "utf8"));
13
19
  }
14
20
 
15
21
  function writeSettings(settings) {
@@ -38,6 +44,7 @@ function resolveProfileName(profile) {
38
44
 
39
45
  module.exports = {
40
46
  getDefaultProfile,
47
+ legacySettingsPath,
41
48
  readSettings,
42
49
  resolveProfileName,
43
50
  setDefaultProfile,
@@ -51,6 +51,8 @@ test("profile set stores a project default profile used by api calls", async ()
51
51
  const root = createConfigRoot();
52
52
 
53
53
  await capture(() => run(["profile", "set", "dev", "--config-root", root]));
54
+ assert.equal(fs.existsSync(path.join(root, ".evt", "config.json")), true);
55
+ assert.equal(fs.existsSync(path.join(root, "data", ".evt", "config.json")), false);
54
56
 
55
57
  const current = await capture(() => run(["profile", "current", "--config-root", root]));
56
58
  assert.equal(current[0], "dev");
@@ -68,3 +70,13 @@ test("profile set stores a project default profile used by api calls", async ()
68
70
  assert.equal(payload.request.url, "https://dev.example.test/api/todos");
69
71
  assert.equal(payload.request.headers["X-Profile"], "dev");
70
72
  });
73
+
74
+ test("profile default still reads legacy data .evt settings", async () => {
75
+ const root = createConfigRoot();
76
+ write(path.join(root, "data", ".evt", "config.json"), JSON.stringify({
77
+ defaultProfile: "dev"
78
+ }, null, 2));
79
+
80
+ const current = await capture(() => run(["profile", "current", "--config-root", root]));
81
+ assert.equal(current[0], "dev");
82
+ });
@@ -0,0 +1,30 @@
1
+ const fs = require("node:fs");
2
+ const os = require("node:os");
3
+ const path = require("node:path");
4
+ const test = require("node:test");
5
+ const assert = require("node:assert/strict");
6
+ const { readCache, resolveCachePath, writeCache } = require("../src/cache/sessionCache");
7
+ const { defaultCachePath, setConfigRoot } = require("../src/util/paths");
8
+
9
+ test("uses .evt/cache as the default session cache directory", () => {
10
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "evt-cache-new-"));
11
+ setConfigRoot(root);
12
+
13
+ assert.equal(defaultCachePath(), path.join(root, ".evt", "cache", "session.local.json"));
14
+ assert.equal(resolveCachePath(), path.join(root, ".evt", "cache", "session.local.json"));
15
+
16
+ writeCache(undefined, { token: "new-token" });
17
+ assert.equal(fs.existsSync(path.join(root, ".evt", "cache", "session.local.json")), true);
18
+ assert.deepEqual(readCache(), { token: "new-token" });
19
+ });
20
+
21
+ test("reads legacy .cache session cache when new cache does not exist", () => {
22
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "evt-cache-legacy-"));
23
+ setConfigRoot(root);
24
+ fs.mkdirSync(path.join(root, ".cache"), { recursive: true });
25
+ fs.writeFileSync(path.join(root, ".cache", "session.local.json"), JSON.stringify({
26
+ token: "legacy-token"
27
+ }));
28
+
29
+ assert.deepEqual(readCache(), { token: "legacy-token" });
30
+ });