cybertrain 0.3.1 → 0.4.1
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.
- checksums.yaml +4 -4
- data/README.md +82 -2049
- data/cybertrain/cli/attachment.rb +246 -164
- data/cybertrain/cli/authentication.rb +2405 -898
- data/cybertrain/cli/authentication_tests.rb +3175 -0
- data/cybertrain/cli/build.rb +93 -7
- data/cybertrain/cli/component.rb +118 -0
- data/cybertrain/cli/helper.rb +143 -0
- data/cybertrain/cli/job.rb +159 -0
- data/cybertrain/cli/line_diff.rb +216 -0
- data/cybertrain/cli/new_app.rb +17 -7
- data/cybertrain/cli/scaffold.rb +29 -1
- data/cybertrain/cli/templates.rb +405 -29
- data/cybertrain/cli/test_command.rb +301 -0
- data/cybertrain/cli/toolchain.rb +12 -12
- data/cybertrain/cli.rb +145 -24
- data/cybertrain/crypto.rb +136 -0
- data/cybertrain/ident.rb +9 -1
- data/cybertrain/shell.rb +13 -0
- data/cybertrain/test/args.rb +286 -0
- data/cybertrain/test_files.rb +48 -0
- data/cybertrain/version.rb +2 -2
- metadata +11 -2
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Cybertrain::Crypto -- the primitives sessions, cookies and CsrfProtection
|
|
2
|
+
# sign, derive keys and compare with.
|
|
3
|
+
#
|
|
4
|
+
# HMAC-SHA256 is implemented here in pure Ruby over Digest::SHA256.digest,
|
|
5
|
+
# the runtime's own vendored SHA-256 (spikes/NOTES.md numbers table). It
|
|
6
|
+
# was written that way when the `openssl` package was linked only into
|
|
7
|
+
# programs that asked for it; `require "cybertrain"` now loads
|
|
8
|
+
# cybertrain/encryptor.rb, and so openssl, in every program (the encrypted
|
|
9
|
+
# session, spec section 5.1), but this file needs neither and stays usable
|
|
10
|
+
# on its own. {Crypto.derive_key} turns `secret_key_base` into one 32-byte
|
|
11
|
+
# key per purpose (the session, signed cookies, encrypted cookies), so no
|
|
12
|
+
# two uses share a key. The derivation input carries a fixed prefix
|
|
13
|
+
# ({Crypto::KEY_PREFIX}) so a derived key is never the same HMAC as one
|
|
14
|
+
# the framework computes directly under the raw secret (Password's
|
|
15
|
+
# session key tag, Stream's signing key), whose tag may be public. The AES-256-GCM encryption itself is
|
|
16
|
+
# cybertrain/encryptor.rb's.
|
|
17
|
+
require "digest"
|
|
18
|
+
require "securerandom"
|
|
19
|
+
|
|
20
|
+
module Cybertrain
|
|
21
|
+
module Crypto
|
|
22
|
+
BLOCK_SIZE = 64
|
|
23
|
+
HEX_DIGITS = "0123456789abcdef"
|
|
24
|
+
# Domain separation for derive_key: no other HMAC under the raw secret
|
|
25
|
+
# starts with this.
|
|
26
|
+
KEY_PREFIX = "cybertrain key\0"
|
|
27
|
+
|
|
28
|
+
def self.hmac_hex(secret, data)
|
|
29
|
+
Crypto.hex(hmac_digest(secret, data))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Lowercase hex of raw bytes. The result is allocated once at its final
|
|
33
|
+
# size and filled with setbyte (in place on a heap String): appending
|
|
34
|
+
# HEX_DIGITS[i] made a one-character String per digit, 64 per HMAC.
|
|
35
|
+
def self.hex(bytes)
|
|
36
|
+
n = bytes.bytesize
|
|
37
|
+
out = "0" * (n * 2)
|
|
38
|
+
i = 0
|
|
39
|
+
while i < n
|
|
40
|
+
b = bytes.getbyte(i)
|
|
41
|
+
out.setbyte(i * 2, HEX_DIGITS.getbyte((b >> 4) & 0xf))
|
|
42
|
+
out.setbyte(i * 2 + 1, HEX_DIGITS.getbyte(b & 0xf))
|
|
43
|
+
i += 1
|
|
44
|
+
end
|
|
45
|
+
out
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Constant-time byte comparison: every byte pair is examined regardless
|
|
49
|
+
# of an early mismatch, so the running time does not leak how much of a
|
|
50
|
+
# signature or token was guessed correctly. (Strings of different
|
|
51
|
+
# lengths return false at once: the length is not the secret.)
|
|
52
|
+
# @example
|
|
53
|
+
# Cybertrain::Crypto.secure_compare(params[:token].to_s, SetupController.setup_token)
|
|
54
|
+
# @param a [String]
|
|
55
|
+
# @param b [String]
|
|
56
|
+
# @return [Boolean] whether the two hold the same bytes
|
|
57
|
+
# @api public
|
|
58
|
+
def self.secure_compare(a, b)
|
|
59
|
+
return false if a.bytesize != b.bytesize
|
|
60
|
+
|
|
61
|
+
a_bytes = a.bytes
|
|
62
|
+
b_bytes = b.bytes
|
|
63
|
+
diff = 0
|
|
64
|
+
i = 0
|
|
65
|
+
while i < a_bytes.length
|
|
66
|
+
diff |= (a_bytes[i] ^ b_bytes[i])
|
|
67
|
+
i += 1
|
|
68
|
+
end
|
|
69
|
+
diff == 0
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# SecureRandom.hex, through Crypto.hex (SecureRandom.hex appends a
|
|
73
|
+
# one-character String per digit).
|
|
74
|
+
# @example
|
|
75
|
+
# Cybertrain::Crypto.random_token(16) # => "3f9c..." (32 hex digits)
|
|
76
|
+
# @param bytes [Integer] how many random bytes
|
|
77
|
+
# @return [String] twice as many lowercase hex digits
|
|
78
|
+
# @api public
|
|
79
|
+
def self.random_token(bytes = 32)
|
|
80
|
+
Crypto.hex(SecureRandom.random_bytes(bytes))
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# A fresh key for `CYBERTRAIN_ENCRYPTION_KEY`: 32 random bytes as 64
|
|
84
|
+
# lowercase hex digits (what `cybertrain secret --hex` prints). The
|
|
85
|
+
# encryption itself is cybertrain/encryptor.rb's (AES-256-GCM through
|
|
86
|
+
# openssl); making a key needs only SecureRandom.
|
|
87
|
+
# @example
|
|
88
|
+
# Cybertrain::Crypto.encryption_key_hex # => "9b1f..." (64 hex digits)
|
|
89
|
+
# @return [String]
|
|
90
|
+
# @api public
|
|
91
|
+
def self.encryption_key_hex
|
|
92
|
+
Crypto.random_token(32)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# A 32-byte key for one purpose, derived from a secret (normally
|
|
96
|
+
# `secret_key_base`): the HMAC-SHA256 of `"cybertrain key\0" + label`
|
|
97
|
+
# under `secret` (the prefix keeps it apart from the framework's other
|
|
98
|
+
# HMACs under the raw secret). Each
|
|
99
|
+
# use takes its own label ("cybertrain session", "cybertrain signed
|
|
100
|
+
# cookie", "cybertrain encrypted cookie"), so a value made under one key
|
|
101
|
+
# never verifies or decrypts under another, and rotating the secret
|
|
102
|
+
# changes them all.
|
|
103
|
+
# @example
|
|
104
|
+
# Cybertrain::Crypto.derive_key(config.secret_key_base, "cybertrain session").bytesize # => 32
|
|
105
|
+
# @param secret [String]
|
|
106
|
+
# @param label [String] the purpose
|
|
107
|
+
# @return [String] 32 raw bytes
|
|
108
|
+
# @api public
|
|
109
|
+
def self.derive_key(secret, label)
|
|
110
|
+
Crypto.hmac_digest(secret, KEY_PREFIX + label)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# RFC 2104 HMAC over Digest::SHA256, keyed the way every implementation
|
|
114
|
+
# is: a key longer than the block size is hashed down first, a shorter
|
|
115
|
+
# one is zero-padded up to it. The pads start as BLOCK_SIZE copies of
|
|
116
|
+
# 0x36 ("6") and 0x5c ("\\") -- a zero key byte XORed with the pad
|
|
117
|
+
# byte -- and setbyte puts each key byte's XOR over them; `.b` makes
|
|
118
|
+
# them binary so `+ data.b` never meets an encoding mismatch.
|
|
119
|
+
def self.hmac_digest(secret, data)
|
|
120
|
+
key = secret.bytesize > BLOCK_SIZE ? Digest::SHA256.digest(secret) : secret
|
|
121
|
+
ipad = ("6" * BLOCK_SIZE).b
|
|
122
|
+
opad = ("\\" * BLOCK_SIZE).b
|
|
123
|
+
n = key.bytesize
|
|
124
|
+
i = 0
|
|
125
|
+
while i < n
|
|
126
|
+
b = key.getbyte(i)
|
|
127
|
+
ipad.setbyte(i, b ^ 0x36)
|
|
128
|
+
opad.setbyte(i, b ^ 0x5c)
|
|
129
|
+
i += 1
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
inner = Digest::SHA256.digest(ipad + data.b)
|
|
133
|
+
Digest::SHA256.digest(opad + inner)
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
data/cybertrain/ident.rb
CHANGED
|
@@ -29,11 +29,19 @@ module Cybertrain
|
|
|
29
29
|
RESERVED_COLUMN_NAMES = [
|
|
30
30
|
# Cybertrain::Model: its methods and the ivars behind them (`errors`,
|
|
31
31
|
# `persisted` -> @errors, @persisted)
|
|
32
|
-
"errors", "persisted", "attributes", "save", "update", "destroy",
|
|
32
|
+
"errors", "persisted", "attributes", "save", "update", "update_columns", "destroy",
|
|
33
33
|
"reload", "model_name", "to_json", "as_json", "to_param", "to_row",
|
|
34
34
|
"load_row", "set_id", "run_callbacks", "insert_row", "update_row",
|
|
35
35
|
"read_attribute", "write_attribute", "assign_attributes",
|
|
36
36
|
"read_association", "call_view_method", "initialize",
|
|
37
|
+
"create_with_callbacks", "update_with_callbacks", "destroy_with_callbacks",
|
|
38
|
+
# declared associations: dependent:, the caches reload clears,
|
|
39
|
+
# counter_cache
|
|
40
|
+
"destroy_dependents", "reset_association_caches", "counter_cache_created",
|
|
41
|
+
"counter_cache_destroyed", "counter_cache_was", "counter_cache_moved", "counter_cache_columns",
|
|
42
|
+
# validations: the generated `validate :method` calls (unique_value_taken?
|
|
43
|
+
# and validation_condition? end in `?` and need no entry)
|
|
44
|
+
"run_custom_validations",
|
|
37
45
|
# Object methods Ruby or the framework calls on a record without being
|
|
38
46
|
# asked: string interpolation and templates (to_s), error messages
|
|
39
47
|
# (inspect), Hash keys (hash)
|
data/cybertrain/shell.rb
CHANGED
|
@@ -6,6 +6,19 @@ module Cybertrain
|
|
|
6
6
|
# choose. A leaf file with no requires: the CLI (CRuby) and the framework
|
|
7
7
|
# (Spinel) both load it.
|
|
8
8
|
module Shell
|
|
9
|
+
# How the CLI (`cybertrain new`, `db`, `migration`, `server`, `build`)
|
|
10
|
+
# and the development rebuilder run spin for gen and db: in spin's debug
|
|
11
|
+
# mode (-O0 -g). Both tools run for milliseconds, and at -O2 gen takes
|
|
12
|
+
# 38 s to build while its C is one unit (under 4 MiB) and 18 s on four
|
|
13
|
+
# cores once it is split; in debug mode gen builds in 8.5 s and writes
|
|
14
|
+
# the same files
|
|
15
|
+
# (docs/superpowers/specs/2026-11-12-dev-flow-bottlenecks-design.md, C3).
|
|
16
|
+
# spin keeps the mode per executable in build/bin/.<name>.mode, so a
|
|
17
|
+
# debug gen is up to date for the next debug run and the application,
|
|
18
|
+
# built without the prefix, stays a release build. The one definition:
|
|
19
|
+
# the CLI's commands and Dev::Rebuilder::GEN_COMMAND both read it.
|
|
20
|
+
TOOL_SPIN = "SPIN_DEBUG=1 spin"
|
|
21
|
+
|
|
9
22
|
# text single-quoted, each embedded ' closed, escaped and reopened, so sh
|
|
10
23
|
# reads it back as exactly text whatever it contains.
|
|
11
24
|
def self.quote(text)
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
# Cybertrain::Test::Args -- the run-time arguments of `cybertrain test`
|
|
2
|
+
# and of the bundle it compiles (spec section 8, plan decision 11): file or
|
|
3
|
+
# directory arguments keep the tests of those files, `-n NAME` keeps a test
|
|
4
|
+
# whose name or method name is NAME, `-n /TEXT/` one whose name or method
|
|
5
|
+
# name contains TEXT; both combine. No requires beyond the standard
|
|
6
|
+
# library: the CLI checks the arguments with it before compiling, and the
|
|
7
|
+
# compiled bundle filters with it, so the two never disagree.
|
|
8
|
+
module Cybertrain
|
|
9
|
+
module Test
|
|
10
|
+
# The parsed arguments: arg_files (the bundled files kept; empty for
|
|
11
|
+
# all), arg_name (`-n NAME`, "" for none), arg_pattern (the TEXT of
|
|
12
|
+
# `-n /TEXT/`, "" for none) and arg_error ("" when the arguments are
|
|
13
|
+
# good, else the reason printed under {USAGE}, exit status 2).
|
|
14
|
+
# @api private
|
|
15
|
+
class Args
|
|
16
|
+
USAGE = "usage: cybertrain test [FILE|DIR ...] [-n NAME|-n /TEXT/]".freeze
|
|
17
|
+
# What `test/x_test.rb:14` (the place a FAIL line prints) is refused with.
|
|
18
|
+
LINE_FILTER = "line filters are not supported; give the file, and -n for the name".freeze
|
|
19
|
+
# The characters `-n /TEXT/` refuses in TEXT ({pattern_problem}).
|
|
20
|
+
REGEXP_CHARACTERS = ["^", "$", "\\", "*", "+", "[", "]", "{", "}", "|"].freeze
|
|
21
|
+
# The line a run prints when a filter kept no test (the run still
|
|
22
|
+
# exits 0: 0 tests is not a failure, spec section 8).
|
|
23
|
+
NOTHING_MATCHED = "no test matched the filter".freeze
|
|
24
|
+
# The digits of a method name's `_u<hex>_` ({method_for}).
|
|
25
|
+
HEX = "0123456789abcdef".freeze
|
|
26
|
+
|
|
27
|
+
attr_reader :arg_files, :arg_name, :arg_pattern, :arg_error
|
|
28
|
+
|
|
29
|
+
def initialize(arg_files, arg_name, arg_pattern, arg_error)
|
|
30
|
+
@arg_files = arg_files
|
|
31
|
+
@arg_name = arg_name
|
|
32
|
+
@arg_pattern = arg_pattern
|
|
33
|
+
@arg_error = arg_error
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Parses argv against `files` (the application's test files,
|
|
37
|
+
# "test/models/article_test.rb", ...; Cybertrain::TestFiles.list) of
|
|
38
|
+
# the application at `root`. A file argument may be written
|
|
39
|
+
# `./test/x_test.rb` or as an absolute path under root; a directory
|
|
40
|
+
# keeps every file under it; after `--` every argument is a file or
|
|
41
|
+
# directory, even one starting with `-`. Anything else (an unknown
|
|
42
|
+
# option, `-n` with no value, `-n /TEXT/` whose TEXT holds a regexp
|
|
43
|
+
# character, FILE:LINE, a path that is no test file) answers an Args
|
|
44
|
+
# whose arg_error says so. A later `-n` replaces an earlier one.
|
|
45
|
+
# @param argv [Array<String>]
|
|
46
|
+
# @param files [Array<String>]
|
|
47
|
+
# @param root [String]
|
|
48
|
+
# @return [Cybertrain::Test::Args]
|
|
49
|
+
def self.parse(argv, files, root)
|
|
50
|
+
picked = Array.new(0) { "" }
|
|
51
|
+
name = ""
|
|
52
|
+
pattern = ""
|
|
53
|
+
options = true
|
|
54
|
+
i = 0
|
|
55
|
+
while i < argv.length
|
|
56
|
+
arg = argv[i]
|
|
57
|
+
if options && arg == "--"
|
|
58
|
+
options = false
|
|
59
|
+
i += 1
|
|
60
|
+
elsif options && arg == "-n"
|
|
61
|
+
value = i + 1 < argv.length ? argv[i + 1] : ""
|
|
62
|
+
return refused("-n needs a name or /text/") if value.empty?
|
|
63
|
+
|
|
64
|
+
return refused("-n needs a name or /text/") if value == "//"
|
|
65
|
+
|
|
66
|
+
if value.length >= 2 && value.start_with?("/") && value.end_with?("/")
|
|
67
|
+
pattern = value[1, value.length - 2].to_s
|
|
68
|
+
problem = pattern_problem(pattern)
|
|
69
|
+
return refused(problem) unless problem.empty?
|
|
70
|
+
|
|
71
|
+
name = ""
|
|
72
|
+
else
|
|
73
|
+
name = value
|
|
74
|
+
pattern = ""
|
|
75
|
+
end
|
|
76
|
+
i += 2
|
|
77
|
+
elsif options && arg.start_with?("-")
|
|
78
|
+
return refused("unknown option #{arg}")
|
|
79
|
+
else
|
|
80
|
+
matched = matching_files(arg, files, root)
|
|
81
|
+
return refused(line_filter?(arg, files, root) ? LINE_FILTER : "no test file at #{arg}") if matched.empty?
|
|
82
|
+
|
|
83
|
+
matched.each { |f| picked << f unless picked.include?(f) }
|
|
84
|
+
i += 1
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
Args.new(picked, name, pattern, "")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def self.refused(reason)
|
|
91
|
+
Args.new(Array.new(0) { "" }, "", "", reason)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Why `-n /TEXT/` is refused, "" when it is not: TEXT holds a
|
|
95
|
+
# character only a regexp means something by (Rails' `-n /x/` is a
|
|
96
|
+
# regexp; here the text between the slashes is a plain substring).
|
|
97
|
+
# `.`, `?` and parentheses are taken as themselves: test names hold
|
|
98
|
+
# them.
|
|
99
|
+
# @param pattern [String]
|
|
100
|
+
# @return [String]
|
|
101
|
+
def self.pattern_problem(pattern)
|
|
102
|
+
bad = ""
|
|
103
|
+
plain = +""
|
|
104
|
+
pattern.each_char do |ch|
|
|
105
|
+
if REGEXP_CHARACTERS.include?(ch)
|
|
106
|
+
bad = ch if bad.empty?
|
|
107
|
+
else
|
|
108
|
+
plain << ch
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
return "" if bad.empty?
|
|
112
|
+
|
|
113
|
+
hint = plain.empty? ? "" : " (-n /#{plain}/)"
|
|
114
|
+
"-n /#{pattern}/: the text between the slashes is a plain substring of the test name, not a regexp " \
|
|
115
|
+
"(#{bad} would be looked for as itself); write the text to look for#{hint}"
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Whether arg is FILE:LINE (the place a FAIL line prints) naming one
|
|
119
|
+
# of `files`.
|
|
120
|
+
def self.line_filter?(arg, files, root)
|
|
121
|
+
colon = -1
|
|
122
|
+
digits = true
|
|
123
|
+
k = arg.length - 1
|
|
124
|
+
while k >= 0
|
|
125
|
+
ch = arg[k].to_s
|
|
126
|
+
if ch == ":"
|
|
127
|
+
colon = k
|
|
128
|
+
break
|
|
129
|
+
end
|
|
130
|
+
digits = false unless ch >= "0" && ch <= "9"
|
|
131
|
+
k -= 1
|
|
132
|
+
end
|
|
133
|
+
return false if colon <= 0 || colon == arg.length - 1 || !digits
|
|
134
|
+
|
|
135
|
+
!matching_files(arg[0, colon].to_s, files, root).empty?
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# The files of `files` that `arg` names: the file itself, or every
|
|
139
|
+
# file under the directory it names.
|
|
140
|
+
def self.matching_files(arg, files, root)
|
|
141
|
+
rel = arg
|
|
142
|
+
rel = rel[2, rel.length - 2].to_s while rel.start_with?("./")
|
|
143
|
+
prefix = root.end_with?("/") ? root : "#{root}/"
|
|
144
|
+
if !root.empty? && rel.start_with?(prefix)
|
|
145
|
+
rel = rel[prefix.length, rel.length - prefix.length].to_s
|
|
146
|
+
elsif !root.empty? && rel.start_with?("/")
|
|
147
|
+
# The same place spelled through a symlink (macOS's /var is
|
|
148
|
+
# /private/var; Dir.pwd answers the real spelling).
|
|
149
|
+
real_root = real_path(root)
|
|
150
|
+
real_prefix = real_root.end_with?("/") ? real_root : "#{real_root}/"
|
|
151
|
+
real = real_path(rel)
|
|
152
|
+
rel = real[real_prefix.length, real.length - real_prefix.length].to_s if real.start_with?(real_prefix)
|
|
153
|
+
end
|
|
154
|
+
rel = rel[0, rel.length - 1].to_s while rel.length > 1 && rel.end_with?("/")
|
|
155
|
+
out = Array.new(0) { "" }
|
|
156
|
+
if files.include?(rel)
|
|
157
|
+
out << rel
|
|
158
|
+
return out
|
|
159
|
+
end
|
|
160
|
+
under = "#{rel}/"
|
|
161
|
+
files.each { |f| out << f if f.start_with?(under) }
|
|
162
|
+
out
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# path with every symlink resolved: File.realpath of its longest
|
|
166
|
+
# existing part, the rest appended as written. The comparisons of the
|
|
167
|
+
# CLI and the bundle use it, so /var/... and /private/var/... (or a
|
|
168
|
+
# checkout reached through a link) are one place.
|
|
169
|
+
# @param path [String]
|
|
170
|
+
# @return [String]
|
|
171
|
+
def self.real_path(path)
|
|
172
|
+
return File.realpath(path) if File.exist?(path)
|
|
173
|
+
|
|
174
|
+
parent = File.dirname(path)
|
|
175
|
+
return path if parent == path
|
|
176
|
+
|
|
177
|
+
base = real_path(parent)
|
|
178
|
+
base.end_with?("/") ? "#{base}#{File.basename(path)}" : "#{base}/#{File.basename(path)}"
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# The method name of a test (spec 5.2; gen's rewrite uses this one):
|
|
182
|
+
# `test_` and the name with every ASCII character outside
|
|
183
|
+
# [A-Za-z0-9_] turned into `_` and every other character into
|
|
184
|
+
# `_u<hex>_`, the lowercase hex of its code point closed by `_`
|
|
185
|
+
# ("ログ" -> test__u30ed__u30b0_, "éa" -> test__ue9_a), so that names
|
|
186
|
+
# in another script do not collide and an escape never runs into
|
|
187
|
+
# the hex digits or letters after it. Each character is replaced on
|
|
188
|
+
# its own: adjacent escapes are simply concatenated, and a non-word
|
|
189
|
+
# ASCII character after one adds its own `_` ("é!" -> test__ue9__).
|
|
190
|
+
# ASCII is kept as written, so a name holding an escape's text
|
|
191
|
+
# ("x_u3042_") has the method name of the character ("xあ"); within
|
|
192
|
+
# one class gen refuses such a pair (TestScan.refuse_collision). Read
|
|
193
|
+
# byte by byte as UTF-8, the same under Spinel and CRuby whatever
|
|
194
|
+
# the String's encoding tag; a byte that starts no well-formed
|
|
195
|
+
# sequence is `_u<hex>_` of the byte.
|
|
196
|
+
# @param name [String]
|
|
197
|
+
# @return [String]
|
|
198
|
+
def self.method_for(name)
|
|
199
|
+
s = name.to_s
|
|
200
|
+
out = +"test_"
|
|
201
|
+
n = s.bytesize
|
|
202
|
+
i = 0
|
|
203
|
+
while i < n
|
|
204
|
+
b = s.getbyte(i).to_i
|
|
205
|
+
if b < 128
|
|
206
|
+
word = (b >= 97 && b <= 122) || (b >= 65 && b <= 90) || (b >= 48 && b <= 57) || b == 95
|
|
207
|
+
out << (word ? s.byteslice(i, 1).to_s : "_")
|
|
208
|
+
i += 1
|
|
209
|
+
else
|
|
210
|
+
size = utf8_size(b)
|
|
211
|
+
code = utf8_code(s, i, size)
|
|
212
|
+
if code < 0
|
|
213
|
+
size = 1
|
|
214
|
+
code = b
|
|
215
|
+
end
|
|
216
|
+
out << "_u" << hex(code) << "_"
|
|
217
|
+
i += size
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
out
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# How many bytes the UTF-8 sequence led by byte b takes (1 for a byte
|
|
224
|
+
# that leads none).
|
|
225
|
+
def self.utf8_size(b)
|
|
226
|
+
return 2 if b >= 0xC2 && b <= 0xDF
|
|
227
|
+
return 3 if b >= 0xE0 && b <= 0xEF
|
|
228
|
+
return 4 if b >= 0xF0 && b <= 0xF4
|
|
229
|
+
|
|
230
|
+
1
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
# The code point of the `size`-byte sequence at s's byte i; -1 when
|
|
234
|
+
# it is cut short or malformed (or size is 1: no lead byte).
|
|
235
|
+
def self.utf8_code(text, i, size)
|
|
236
|
+
s = text.to_s
|
|
237
|
+
return -1 if size < 2 || i + size > s.bytesize
|
|
238
|
+
|
|
239
|
+
b = s.getbyte(i).to_i
|
|
240
|
+
code = size == 2 ? b & 0x1F : (size == 3 ? b & 0x0F : b & 0x07)
|
|
241
|
+
k = 1
|
|
242
|
+
while k < size
|
|
243
|
+
c = s.getbyte(i + k).to_i
|
|
244
|
+
return -1 if c < 0x80 || c > 0xBF
|
|
245
|
+
|
|
246
|
+
code = (code << 6) | (c & 0x3F)
|
|
247
|
+
k += 1
|
|
248
|
+
end
|
|
249
|
+
code
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
# n in lowercase hex ("3042").
|
|
253
|
+
def self.hex(n)
|
|
254
|
+
return "0" if n.zero?
|
|
255
|
+
|
|
256
|
+
digits = +""
|
|
257
|
+
v = n
|
|
258
|
+
while v.positive?
|
|
259
|
+
digits = "#{HEX[v % 16]}#{digits}"
|
|
260
|
+
v /= 16
|
|
261
|
+
end
|
|
262
|
+
digits
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
# Whether a file or name filter was given (a run that keeps no test
|
|
266
|
+
# then prints {NOTHING_MATCHED}).
|
|
267
|
+
# @return [Boolean]
|
|
268
|
+
def filtered?
|
|
269
|
+
!@arg_files.empty? || !@arg_name.empty? || !@arg_pattern.empty?
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
# Whether the test `name` (method `meth`) of `file` is kept.
|
|
273
|
+
# @param file [String]
|
|
274
|
+
# @param name [String]
|
|
275
|
+
# @param meth [String]
|
|
276
|
+
# @return [Boolean]
|
|
277
|
+
def keep?(file, name, meth)
|
|
278
|
+
return false unless @arg_files.empty? || @arg_files.include?(file)
|
|
279
|
+
return name == @arg_name || meth == @arg_name unless @arg_name.empty?
|
|
280
|
+
return !name.index(@arg_pattern).nil? || !meth.index(@arg_pattern).nil? unless @arg_pattern.empty?
|
|
281
|
+
|
|
282
|
+
true
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Which files of an application are its tests (spec 5.2, 8): shared by gen
|
|
2
|
+
# (Gen::TestScan) and `cybertrain test`, so the two never disagree. No
|
|
3
|
+
# requires: the CLI loads it without the generator.
|
|
4
|
+
module Cybertrain
|
|
5
|
+
module TestFiles
|
|
6
|
+
HELPER = "test/test_helper.rb".freeze
|
|
7
|
+
|
|
8
|
+
# "test/models/article_test.rb", ... under root: every
|
|
9
|
+
# test/**/*_test.rb and every test/*.rb except test/test_helper.rb,
|
|
10
|
+
# never a file under test/support/ or test/fixtures/; sorted.
|
|
11
|
+
def self.list(root)
|
|
12
|
+
out = Array.new(0) { "" }
|
|
13
|
+
walk(root, "test", out)
|
|
14
|
+
picked = Array.new(0) { "" }
|
|
15
|
+
out.each do |rel|
|
|
16
|
+
next if rel == HELPER
|
|
17
|
+
next if rel.start_with?("test/support/") || rel.start_with?("test/fixtures/")
|
|
18
|
+
|
|
19
|
+
top = rel.index("/", 5).nil?
|
|
20
|
+
picked << rel if top || rel.end_with?("_test.rb")
|
|
21
|
+
end
|
|
22
|
+
picked.sort
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# test/support/**/*.rb under root, sorted.
|
|
26
|
+
def self.support_files(root)
|
|
27
|
+
out = Array.new(0) { "" }
|
|
28
|
+
walk(root, "test/support", out)
|
|
29
|
+
out.sort
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Appends every .rb file under root/rel (as "rel/..."), depth first.
|
|
33
|
+
def self.walk(root, rel, out)
|
|
34
|
+
dir = "#{root}/#{rel}"
|
|
35
|
+
return nil unless File.directory?(dir)
|
|
36
|
+
|
|
37
|
+
Dir.children(dir).sort.each do |entry|
|
|
38
|
+
child = "#{rel}/#{entry}"
|
|
39
|
+
if File.directory?("#{root}/#{child}")
|
|
40
|
+
walk(root, child, out)
|
|
41
|
+
elsif entry.end_with?(".rb")
|
|
42
|
+
out << child
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
nil
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
data/cybertrain/version.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Cybertrain
|
|
2
|
-
VERSION = "0.
|
|
2
|
+
VERSION = "0.4.1"
|
|
3
3
|
|
|
4
4
|
# Where `cybertrain new` points an app's spin.toml by default: the git tag
|
|
5
5
|
# "v#{VERSION}" of this repository. Kept here because the gem (CRuby) and
|
|
@@ -8,7 +8,7 @@ module Cybertrain
|
|
|
8
8
|
|
|
9
9
|
# The Spinel release cybertrain is written and tested against: the tag of
|
|
10
10
|
# SPINEL_REPOSITORY that `cybertrain setup` builds, and CI's SPINEL_TAG.
|
|
11
|
-
SPINEL_TAG = "2026.
|
|
11
|
+
SPINEL_TAG = "2026.11.04.7026"
|
|
12
12
|
|
|
13
13
|
# Where that tag lives: the saeki-mototsune fork of matz/spinel, which
|
|
14
14
|
# carries the fixes cybertrain needs ahead of an upstream release.
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cybertrain
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Saeki Mototsune
|
|
@@ -26,14 +26,23 @@ files:
|
|
|
26
26
|
- cybertrain/cli.rb
|
|
27
27
|
- cybertrain/cli/attachment.rb
|
|
28
28
|
- cybertrain/cli/authentication.rb
|
|
29
|
+
- cybertrain/cli/authentication_tests.rb
|
|
29
30
|
- cybertrain/cli/build.rb
|
|
31
|
+
- cybertrain/cli/component.rb
|
|
32
|
+
- cybertrain/cli/helper.rb
|
|
33
|
+
- cybertrain/cli/job.rb
|
|
34
|
+
- cybertrain/cli/line_diff.rb
|
|
30
35
|
- cybertrain/cli/new_app.rb
|
|
31
36
|
- cybertrain/cli/scaffold.rb
|
|
32
37
|
- cybertrain/cli/templates.rb
|
|
38
|
+
- cybertrain/cli/test_command.rb
|
|
33
39
|
- cybertrain/cli/toolchain.rb
|
|
40
|
+
- cybertrain/crypto.rb
|
|
34
41
|
- cybertrain/generator/inflector.rb
|
|
35
42
|
- cybertrain/ident.rb
|
|
36
43
|
- cybertrain/shell.rb
|
|
44
|
+
- cybertrain/test/args.rb
|
|
45
|
+
- cybertrain/test_files.rb
|
|
37
46
|
- cybertrain/version.rb
|
|
38
47
|
- exe/cybertrain
|
|
39
48
|
homepage: https://github.com/saeki-mototsune/cybertrain
|
|
@@ -56,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
56
65
|
- !ruby/object:Gem::Version
|
|
57
66
|
version: '0'
|
|
58
67
|
requirements: []
|
|
59
|
-
rubygems_version: 4.0.
|
|
68
|
+
rubygems_version: 4.0.20
|
|
60
69
|
specification_version: 4
|
|
61
70
|
summary: 'The cybertrain CLI: scaffold Rails-shaped apps for the Spinel AOT Ruby compiler'
|
|
62
71
|
test_files: []
|