kryptheon 0.1.41 → 0.1.43

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.
@@ -180,7 +180,8 @@ function flowPrompt(t, lastPass) {
180
180
 
181
181
  function countRecordings(root) {
182
182
  try {
183
- return fs.readdirSync(path.join(root, 'tests')).filter((n) => /\.(spec|test)\.[cm]?[jt]s$/.test(n)).length;
183
+ // Recordings only - not the project's own unit tests in tests/.
184
+ return require('./kryptheon-testfiles.js').recordingNames(path.join(root, 'tests')).length;
184
185
  } catch (err) {
185
186
  return 0;
186
187
  }
@@ -667,7 +668,30 @@ function appAddress(value) {
667
668
  const text = value.trim();
668
669
  if (!text || text.length > 2000 || /[\s\x00-\x1f]/.test(text) || text.startsWith('-')) return null;
669
670
  if (/^[a-z][a-z0-9+.-]*:\/\//i.test(text)) return /^https?:\/\/[^/]/i.test(text) ? text : null;
670
- return /^[a-z0-9.-]+(:\d{1,5})?(\/\S*)?$/i.test(text) ? text : null;
671
+ // A path never starts with "//": "http//localhost:3000" is a mistyped
672
+ // scheme, not a host called "http".
673
+ return /^[a-z0-9.-]+(:\d{1,5})?(\/(?!\/)\S*)?$/i.test(text) ? text : null;
674
+ }
675
+
676
+ /**
677
+ * What was meant, when an address was typed with its start mistyped:
678
+ * "ttp://127.0.0.1:4180" (blind round 13, the first letter lost), "htp://",
679
+ * "http//", "http:/", "htps://". Null when it does not look like that.
680
+ */
681
+ function meantAddress(value) {
682
+ const text = String(value || '').trim();
683
+ const m = /^(h?t{1,3}p{1,2}(s?)|htps|hhttps?)(:\/{0,3}|\/{1,3}|:)(?!\/)(\S+)$/i.exec(text);
684
+ if (!m) return null;
685
+ const secure = /s$/i.test(m[1]);
686
+ const fixed = (secure ? 'https://' : 'http://') + m[4];
687
+ return fixed !== text && appAddress(fixed) ? fixed : null;
688
+ }
689
+
690
+ function notAnAddress(value, example) {
691
+ const meant = meantAddress(value);
692
+ return meant
693
+ ? 'that is not a web address - did you mean ' + meant + '?'
694
+ : 'that is not a web address - it should look like ' + example;
671
695
  }
672
696
 
673
697
  /** The connection string as given, or null when there is none or it is absurd. */
@@ -873,7 +897,7 @@ function createServer(root, options) {
873
897
  }
874
898
  if (url.pathname === '/api/record' && typeof opts.record === 'function') {
875
899
  const address = appAddress(input.url);
876
- if (!address) return json(res, 400, { ok: false, why: 'that is not a web address - it should look like http://localhost:3000' });
900
+ if (!address) return json(res, 400, { ok: false, why: notAnAddress(input.url, 'http://localhost:3000') });
877
901
  const phone = input.phone === true;
878
902
  return begin('record', 'Recording ' + address + (phone ? ' at phone size' : ''),
879
903
  'npx kryptheon record ' + address + (phone ? ' --phone' : ''), (say) => opts.record(address, say, { phone: phone }));
@@ -913,7 +937,7 @@ function createServer(root, options) {
913
937
  // outside check start from it. Empty clears it.
914
938
  const raw = typeof input.address === 'string' ? input.address.trim() : '';
915
939
  const address = raw ? appAddress(raw) : '';
916
- if (address === null) return json(res, 400, { ok: false, why: 'that is not a web address - it should look like https://my-app.lovable.app' });
940
+ if (address === null) return json(res, 400, { ok: false, why: notAnAddress(raw, 'https://my-app.lovable.app') });
917
941
  const full = address && !/^https?:\/\//i.test(address) ? 'https://' + address : address;
918
942
  return saveAppAddress(store.pathsFor(root, env), full)
919
943
  ? json(res, 200, { ok: true, address: full })
@@ -969,6 +993,7 @@ module.exports = {
969
993
  buildState: buildState,
970
994
  flowPrompt: flowPrompt,
971
995
  appAddress: appAddress,
996
+ meantAddress: meantAddress,
972
997
  secretsOf: secretsOf,
973
998
  hideSecrets: hideSecrets,
974
999
  hideSecretsIn: hideSecretsIn,
@@ -113,7 +113,7 @@ function chooseFromList(names, answer) {
113
113
  const lower = said.toLowerCase();
114
114
  const matches = list.filter((name) => {
115
115
  const n = String(name).toLowerCase();
116
- return n === lower || n === lower + '.spec.js' || n.replace(/\.spec\.js$/, '') === lower;
116
+ return n === lower || n === lower + '.spec.js' || n.replace(/\.(spec|kryptheon)\.js$/, '') === lower;
117
117
  });
118
118
  if (matches.length === 1) return { action: 'remove', names: matches };
119
119
  if (matches.length > 1) {
@@ -0,0 +1,98 @@
1
+ // Which files in tests/ are Kryptheon's recordings, and what a new one is
2
+ // called.
3
+ //
4
+ // Found in blind round 13 (a TypeScript service with vitest): its own unit
5
+ // test, tests/incidents.test.ts, was taken for a recording - check said it
6
+ // "only opens a page and stops", and the dashboard showed "Record your main
7
+ // flows: Done, 1 recording held" before anything was recorded. Then the
8
+ // first real recording, saved as tests/<name>.spec.js, was picked up by the
9
+ // project's own `npm test` (vitest), which failed on it: "Playwright Test did
10
+ // not expect test() to be called here". A tool that breaks the app's own
11
+ // tests is one nobody keeps.
12
+ //
13
+ // So: a recording is a file that uses Playwright or Kryptheon's fixture -
14
+ // anything else in tests/ belongs to the project and is left alone. And in a
15
+ // project whose unit-test runner collects *.spec.js / *.test.js, a new
16
+ // recording is saved as <name>.kryptheon.js, which only Kryptheon runs.
17
+
18
+ const fs = require('fs');
19
+ const path = require('path');
20
+
21
+ const SPEC_NAME = /\.(spec|test)\.[cm]?[jt]sx?$/;
22
+ const OWN_NAME = /\.kryptheon\.js$/;
23
+ // What a recording imports: Playwright directly (older or hand-made ones,
24
+ // repaired by check) or the fixture - by package name, or by any path that
25
+ // ends in kryptheon-fixture(.js), relative or absolute.
26
+ const USES_PLAYWRIGHT = /(['"`])(?:@playwright\/test|[^'"`\r\n]*kryptheon-fixture(?:\.js)?)\1/;
27
+
28
+ /** Whether this file in tests/ is one of Kryptheon's recordings. */
29
+ function isRecordingFile(name, source) {
30
+ if (!SPEC_NAME.test(name) && !OWN_NAME.test(name)) return false;
31
+ return USES_PLAYWRIGHT.test(String(source || ''));
32
+ }
33
+
34
+ /** The recordings in a tests folder, as paths relative to it. */
35
+ function recordingNames(testsDir) {
36
+ let entries = [];
37
+ try {
38
+ entries = fs.readdirSync(testsDir, { recursive: true });
39
+ } catch (err) {
40
+ try {
41
+ entries = fs.readdirSync(testsDir);
42
+ } catch (err2) {
43
+ return [];
44
+ }
45
+ }
46
+ return entries.map(String).filter((name) => {
47
+ if (!SPEC_NAME.test(name) && !OWN_NAME.test(name)) return false;
48
+ try {
49
+ return isRecordingFile(name, fs.readFileSync(path.join(testsDir, name), 'utf8'));
50
+ } catch (err) {
51
+ return false;
52
+ }
53
+ });
54
+ }
55
+
56
+ /**
57
+ * The unit-test runner this project uses that would also collect
58
+ * tests/*.spec.js or tests/*.test.js: 'vitest', 'jest', 'mocha' - or null.
59
+ */
60
+ function unitRunnerOf(projectDir) {
61
+ let pkg = {};
62
+ try {
63
+ pkg = JSON.parse(fs.readFileSync(path.join(projectDir, 'package.json'), 'utf8'));
64
+ } catch (err) {
65
+ pkg = {};
66
+ }
67
+ const deps = Object.assign({}, pkg.dependencies, pkg.devDependencies);
68
+ const script = String((pkg.scripts && pkg.scripts.test) || '');
69
+ let files = [];
70
+ try {
71
+ files = fs.readdirSync(projectDir);
72
+ } catch (err) {
73
+ files = [];
74
+ }
75
+ const has = (re) => files.some((f) => re.test(f));
76
+ if (deps.vitest || /\bvitest\b/.test(script) || has(/^vitest\.config\./)) return 'vitest';
77
+ if (deps.jest || pkg.jest || /\bjest\b/.test(script) || has(/^jest\.config\./)) return 'jest';
78
+ if (deps.mocha || /\bmocha\b/.test(script) || has(/^\.mocharc/)) return 'mocha';
79
+ return null;
80
+ }
81
+
82
+ /** What a new recording's file name ends in, in this project. */
83
+ function recordingExtension(projectDir) {
84
+ return unitRunnerOf(projectDir) ? '.kryptheon.js' : '.spec.js';
85
+ }
86
+
87
+ /** A recording's name without its ending: "login" for login.spec.js or login.kryptheon.js. */
88
+ function bareName(name) {
89
+ return String(name).replace(OWN_NAME, '').replace(/\.spec\.js$/, '');
90
+ }
91
+
92
+ module.exports = {
93
+ isRecordingFile: isRecordingFile,
94
+ recordingNames: recordingNames,
95
+ unitRunnerOf: unitRunnerOf,
96
+ recordingExtension: recordingExtension,
97
+ bareName: bareName,
98
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kryptheon",
3
- "version": "0.1.41",
3
+ "version": "0.1.43",
4
4
  "description": "Record what you do in your app and get plain-language reports when it breaks.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "commonjs",
@@ -28,6 +28,7 @@
28
28
  "kryptheon-heal.js",
29
29
  "kryptheon-selectors.js",
30
30
  "kryptheon-recordings.js",
31
+ "kryptheon-testfiles.js",
31
32
  "kryptheon-cleanup.js",
32
33
  "kryptheon-baselines.js",
33
34
  "kryptheon-project.js",
@@ -52,7 +53,7 @@
52
53
  "@playwright/test": "^1.62.1"
53
54
  },
54
55
  "scripts": {
55
- "check": "node kryptheon-store.check.js && node kryptheon-code.check.js && node kryptheon-constdata.check.js && node kryptheon-accept.check.js && node kryptheon-keys.check.js && node kryptheon-dashboard.check.js && node kryptheon-autostart.check.js && node kryptheon-changes.check.js && node kryptheon-look.check.js && node kryptheon-verify.check.js && node kryptheon-recheck.check.js && node kryptheon-reporter.check.js && node kryptheon-signature.check.js && node kryptheon-signature.stream.check.js && node kryptheon-signature.baseline.check.js && node kryptheon-signature.settle.check.js && node kryptheon-signature.number.check.js && node kryptheon-env.check.js && node kryptheon-watchdog.check.js && node kryptheon-phone.check.js && node kryptheon-homedash.check.js && node kryptheon-record.check.js && node kryptheon-selectors.check.js && node kryptheon-recordings.check.js && node kryptheon-cleanup.check.js && node kryptheon-orphan.check.js && node kryptheon-project.check.js && node kryptheon-setup.check.js && node kryptheon-browser.check.js && node kryptheon-heal.check.js && node kryptheon-load.check.js && node kryptheon-package.check.js",
56
+ "check": "node kryptheon-store.check.js && node kryptheon-code.check.js && node kryptheon-constdata.check.js && node kryptheon-listitems.check.js && node kryptheon-accept.check.js && node kryptheon-keys.check.js && node kryptheon-dashboard.check.js && node kryptheon-autostart.check.js && node kryptheon-changes.check.js && node kryptheon-look.check.js && node kryptheon-verify.check.js && node kryptheon-recheck.check.js && node kryptheon-reporter.check.js && node kryptheon-signature.check.js && node kryptheon-signature.stream.check.js && node kryptheon-signature.baseline.check.js && node kryptheon-signature.settle.check.js && node kryptheon-signature.number.check.js && node kryptheon-env.check.js && node kryptheon-watchdog.check.js && node kryptheon-phone.check.js && node kryptheon-homedash.check.js && node kryptheon-record.check.js && node kryptheon-selectors.check.js && node kryptheon-recordings.check.js && node kryptheon-testfiles.check.js && node kryptheon-cleanup.check.js && node kryptheon-orphan.check.js && node kryptheon-project.check.js && node kryptheon-setup.check.js && node kryptheon-browser.check.js && node kryptheon-heal.check.js && node kryptheon-load.check.js && node kryptheon-package.check.js",
56
57
  "check:store": "node kryptheon-store.check.js",
57
58
  "check:code": "node kryptheon-code.check.js",
58
59
  "check:constdata": "node kryptheon-constdata.check.js",
@@ -81,7 +82,9 @@
81
82
  "check:heal": "node kryptheon-heal.check.js",
82
83
  "check:load": "node kryptheon-load.check.js",
83
84
  "check:package": "node kryptheon-package.check.js",
84
- "prepublishOnly": "node kryptheon-package.check.js"
85
+ "prepublishOnly": "node kryptheon-package.check.js",
86
+ "check:testfiles": "node kryptheon-testfiles.check.js",
87
+ "check:listitems": "node kryptheon-listitems.check.js"
85
88
  },
86
89
  "keywords": [
87
90
  "playwright",
@@ -41,6 +41,9 @@ loadEnv(path.join(USER_DIR, '.env'));
41
41
  module.exports = defineConfig({
42
42
  // The tests belong to the user, so they are found in their folder.
43
43
  testDir: path.join(USER_DIR, 'tests'),
44
+ // Playwright's own pattern, plus <name>.kryptheon.js: the name a recording
45
+ // gets in a project whose unit-test runner would also collect *.spec.js.
46
+ testMatch: ['**/*.@(spec|test).?(c|m)[jt]s?(x)', '**/*.kryptheon.js'],
44
47
  // Screenshots and other artefacts default to sitting next to the config,
45
48
  // which once installed means inside node_modules. They belong to the user's
46
49
  // project, so they go to its store - outside the project, where a commit of