@andrian.yablonskyy/thub-common 1.0.25 → 1.0.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrian.yablonskyy/thub-common",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "description": "Shared job-spec schema, state enums and a thin API client used by the Agent and Client",
5
5
  "main": "src/index.js",
6
6
  "files": [
package/src/index.js CHANGED
@@ -20,5 +20,6 @@ module.exports = {
20
20
  ...require('./datetime'),
21
21
  ...require('./cron'),
22
22
  ...require('./client-config'),
23
+ ...require('./split-args'),
23
24
  ApiClient: require('./api-client').ApiClient
24
25
  };
@@ -89,7 +89,13 @@ const DOCKER_IMAGE_PATTERN =
89
89
  properties: {
90
90
  url: { type: 'string', minLength: 1, maxLength: 2048 },
91
91
  ref: { type: 'string', maxLength: 255, pattern: GIT_REF_PATTERN },
92
- depth: { type: 'integer', minimum: 0, maximum: 100000, default: 1 }
92
+ depth: { type: 'integer', minimum: 0, maximum: 100000, default: 1 },
93
+ // Extra git options (`--git-options`), shell-quoted, inserted
94
+ // between `git` and its subcommand on the Client — e.g.
95
+ // -c core.sshCommand="ssh -i ~/.ssh/lab_key -p 2222". Stored with
96
+ // the job and visible like the rest of it: reference key files on
97
+ // the Client rather than putting secrets here.
98
+ options: { type: 'string', minLength: 1, maxLength: 1024 }
93
99
  }
94
100
  },
95
101
  timeoutSec: { type: 'integer', minimum: 1, default: 1800 },
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @file packages/shared/src/split-args.js
3
+ * @description Splits a command-line options string into arguments the way a POSIX shell would quote them —
4
+ * without running a shell (for `thub run --git-options`)
5
+ *
6
+ * @author Andrian Yablonskyy
7
+ * @copyright Copyright (c) 2026 Andrian Yablonskyy. All rights reserved.
8
+ *
9
+ * This file is part of TestHub and is proprietary and confidential.
10
+ * Unauthorized copying, modification, distribution, or use of this file,
11
+ * via any medium, is strictly prohibited without prior written permission
12
+ * from AdSystem.PRO.
13
+ */
14
+
15
+ 'use strict';
16
+
17
+ // Whitespace separates arguments; '...' is literal; "..." keeps spaces, with
18
+ // \" \\ \$ \` escaped; a backslash outside quotes escapes the next
19
+ // character. No expansion of any kind ($VAR, ~, globs) — the result goes
20
+ // straight to execFile. Throws on an unterminated quote or trailing "\".
21
+ function splitArgs(text){
22
+ const args = [],
23
+ s = String(text ?? '');
24
+ let current = null,
25
+ i = 0;
26
+ const push = (ch) => {
27
+ current = (current ?? '') + ch;
28
+ };
29
+ while (i < s.length){
30
+ const ch = s[i];
31
+ if (/\s/.test(ch)){
32
+ if (current !== null){
33
+ args.push(current);
34
+ current = null;
35
+ }
36
+ i++;
37
+ }
38
+ else if (ch === '\''){
39
+ const end = s.indexOf('\'', i + 1);
40
+ if (end < 0){
41
+ throw new Error('unterminated \' quote');
42
+ }
43
+ push(s.slice(i + 1, end));
44
+ i = end + 1;
45
+ }
46
+ else if (ch === '"'){
47
+ let j = i + 1,
48
+ closed = false;
49
+ push('');
50
+ while (j < s.length){
51
+ if (s[j] === '\\' && /["\\$`]/.test(s[j + 1] || '')){
52
+ push(s[j + 1]);
53
+ j += 2;
54
+ }
55
+ else if (s[j] === '"'){
56
+ closed = true;
57
+ j++;
58
+ break;
59
+ }
60
+ else {
61
+ push(s[j]);
62
+ j++;
63
+ }
64
+ }
65
+ if (!closed){
66
+ throw new Error('unterminated " quote');
67
+ }
68
+ i = j;
69
+ }
70
+ else if (ch === '\\'){
71
+ if (i + 1 >= s.length){
72
+ throw new Error('trailing \\');
73
+ }
74
+ push(s[i + 1]);
75
+ i += 2;
76
+ }
77
+ else {
78
+ push(ch);
79
+ i++;
80
+ }
81
+ }
82
+ if (current !== null){
83
+ args.push(current);
84
+ }
85
+ return args;
86
+ }
87
+
88
+ module.exports = { splitArgs };
@@ -15,7 +15,8 @@
15
15
 
16
16
  const Ajv = require('ajv'),
17
17
  addFormats = require('ajv-formats'),
18
- { jobSpecSchema } = require('./job-spec.schema');
18
+ { jobSpecSchema } = require('./job-spec.schema'),
19
+ { splitArgs } = require('./split-args');
19
20
 
20
21
  const ajv = new Ajv({ useDefaults: true, allErrors: true, strict: false });
21
22
  addFormats(ajv);
@@ -63,6 +64,14 @@ function crossFieldErrors(spec){
63
64
  if (spec.git && !GIT_URL.test(spec.git.url || '')){
64
65
  errors.push('/git/url must be an https://, http://, ssh:// or git:// URL, or user@host:path');
65
66
  }
67
+ if (spec.git?.options){
68
+ try {
69
+ splitArgs(spec.git.options);
70
+ }
71
+ catch (err){
72
+ errors.push(`/git/options can't be split into arguments: ${err.message}`);
73
+ }
74
+ }
66
75
  return errors;
67
76
  }
68
77