judgelint 0.1.10-aarch64-linux → 0.2.1-aarch64-linux
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/CHANGELOG.md +47 -0
- data/README.md +51 -12
- data/exe/judgelint +9 -9
- data/libexec/judgelint +0 -0
- metadata +3 -26
- data/lib/judgelint/cache.rb +0 -344
- data/lib/judgelint/changes.rb +0 -87
- data/lib/judgelint/cli.rb +0 -252
- data/lib/judgelint/client.rb +0 -210
- data/lib/judgelint/config.rb +0 -162
- data/lib/judgelint/errors.rb +0 -14
- data/lib/judgelint/glob.rb +0 -77
- data/lib/judgelint/paint.rb +0 -46
- data/lib/judgelint/pool.rb +0 -44
- data/lib/judgelint/protocol.rb +0 -122
- data/lib/judgelint/providers.rb +0 -78
- data/lib/judgelint/question.rb +0 -159
- data/lib/judgelint/reporter.rb +0 -219
- data/lib/judgelint/rule.rb +0 -167
- data/lib/judgelint/runner.rb +0 -481
- data/lib/judgelint/scaffold.rb +0 -66
- data/lib/judgelint/source.rb +0 -105
- data/lib/judgelint/spec.rb +0 -240
- data/lib/judgelint/usage.rb +0 -53
- data/lib/judgelint/verdict.rb +0 -71
- data/lib/judgelint/version.rb +0 -5
- data/lib/judgelint.rb +0 -60
- data/lib/rubygems_plugin.rb +0 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cdcc8e2aac141c94d2f7309f811f6c5826856360fe0370147a9c3a271cea8e4b
|
|
4
|
+
data.tar.gz: 93772aa61c39089407ebc0b8c772b459b6d278ae5da23e994af42e595038145e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 88b7e71265b5cd6def316ea31d4afee6e978be6443b85dc86525fe2eb4f1a8ce69d87c32ab244600987cbbac2bf0cffa5cb64ce8b71bd2614e4bd5a331ccf2e5
|
|
7
|
+
data.tar.gz: b3021fb040ca2cdca13d0c0d8f504761aa48b95999d4c1b7885277a5272bdf9b8178200a1962a700a2d32076b2be57fef0468e761d9385f4b254beb12e6d0adc
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1 (2026-10-29)
|
|
4
|
+
|
|
5
|
+
Security fixes, after two reviews of 0.2.0. A pull request could change the
|
|
6
|
+
config or specs to send code and environment variables to its own server,
|
|
7
|
+
read files outside the project, or pass with answers it made up.
|
|
8
|
+
|
|
9
|
+
- `--pr` reads `.judgelint.yml`, the specs and the cache from the base
|
|
10
|
+
branch, not the pull request.
|
|
11
|
+
- Every file sent to a model, including `context:` files and a directory
|
|
12
|
+
rule's files, must be inside the project, not reached through a link that
|
|
13
|
+
leaves it, not ignored by git, not binary, and at most 4 MB.
|
|
14
|
+
- A provider pointed at another `api_base` doesn't get the provider's key;
|
|
15
|
+
set `api_key_env` for it. Its answers are cached apart.
|
|
16
|
+
- Plain http goes only to localhost. Redirects aren't followed. Responses
|
|
17
|
+
are capped at 16 MB, and a request at 60 seconds.
|
|
18
|
+
- Under `--base` or `--pr`, a changed file that's skipped or refused fails
|
|
19
|
+
the run.
|
|
20
|
+
- An added line that looks like a diff header no longer hides changed lines.
|
|
21
|
+
- Malformed answers and cached values that aren't probabilities are errors
|
|
22
|
+
or misses, not passes.
|
|
23
|
+
- A model with no price fails the cost check unless you pass `--yes` or set
|
|
24
|
+
`price_per_million`. Servers on localhost cost nothing.
|
|
25
|
+
- Errors show the URL as configured, before `${VAR}` is filled in.
|
|
26
|
+
- Releases carry build attestations, are built with a pinned Rust, and push
|
|
27
|
+
the gems from CI. The gem no longer replaces its command with a link to the
|
|
28
|
+
binary, which could break after an uninstall.
|
|
29
|
+
|
|
30
|
+
## 0.2.0 (2026-10-28)
|
|
31
|
+
|
|
32
|
+
- judgelint is written in Rust now. The gem carries the binary for macOS and
|
|
33
|
+
Linux on arm64 and x86_64. On any other platform the gem says how to build
|
|
34
|
+
it with Cargo; it no longer runs as plain Ruby. There's no Ruby API.
|
|
35
|
+
- It's much faster and smaller than 0.1.10's native binary. On a Mac mini:
|
|
36
|
+
|
|
37
|
+
| Run | 0.1.10 | 0.2.0 |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| Plan 50,000 files | 9.0 s, 140 MB | 1.2 s, 54 MB |
|
|
40
|
+
| Check 5,000 files, nothing cached | 3.4 s, 82 MB | 0.7 s, 19 MB |
|
|
41
|
+
| Check 5,000 files, all cached | 1.5 s, 56 MB | 0.16 s, 16 MB |
|
|
42
|
+
| Check 50,000 files, nothing cached | 23.8 s, 487 MB | 6.4 s, 75 MB |
|
|
43
|
+
|
|
44
|
+
- Answers are cached in `.judgelint/cache.bin`. The old `cache.json` isn't
|
|
45
|
+
read, so the first run asks again; delete it afterward. The new cache is
|
|
46
|
+
about a quarter of the size.
|
|
47
|
+
- Commands, options, specs, config and output formats are the same. Error
|
|
48
|
+
messages are worded differently.
|
|
49
|
+
|
|
3
50
|
## 0.1.10 (2026-10-27)
|
|
4
51
|
|
|
5
52
|
- `check` and `test` use far less memory and run faster. Against 0.1.9 on
|
data/README.md
CHANGED
|
@@ -16,9 +16,14 @@ curl -fsSL https://raw.githubusercontent.com/jpcamara/judgelint/main/install.sh
|
|
|
16
16
|
|
|
17
17
|
The script installs to `~/.local/bin`, or to `$JUDGELINT_INSTALL_DIR`. The
|
|
18
18
|
binaries are on the [releases page](https://github.com/jpcamara/judgelint/releases)
|
|
19
|
-
for macOS and Linux, on arm64 and x86_64. Linux needs glibc 2.
|
|
20
|
-
(Ubuntu 22.04, Debian 12). `gem install judgelint`
|
|
21
|
-
|
|
19
|
+
for macOS and Linux, on arm64 and x86_64. Linux needs glibc 2.34 or newer
|
|
20
|
+
(Ubuntu 22.04, Debian 12, RHEL 9). `gem install judgelint` installs the same
|
|
21
|
+
binary. Anywhere else, build it with Rust:
|
|
22
|
+
`cargo install --git https://github.com/jpcamara/judgelint`.
|
|
23
|
+
|
|
24
|
+
Each release's archives and gems carry a build attestation from the GitHub
|
|
25
|
+
Actions run that built them, from the tagged source. To check one:
|
|
26
|
+
`gh attestation verify judgelint-aarch64-apple-darwin.tar.gz --repo jpcamara/judgelint`.
|
|
22
27
|
|
|
23
28
|
## Getting started
|
|
24
29
|
|
|
@@ -236,6 +241,39 @@ Actions, GitLab, Buildkite, Bitbucket, Azure Pipelines,
|
|
|
236
241
|
`JUDGELINT_BASE_BRANCH`, or `gh`. Fetch enough history for git to find the
|
|
237
242
|
merge base.
|
|
238
243
|
|
|
244
|
+
Under `--base` or `--pr`, a changed file judgelint can't judge fails the
|
|
245
|
+
run: one too large for the model, or one the model refused to answer about.
|
|
246
|
+
|
|
247
|
+
### Pull requests from people you don't trust
|
|
248
|
+
|
|
249
|
+
`--pr` reads `.judgelint.yml`, the specs, and `.judgelint/cache.bin` from the
|
|
250
|
+
base branch, not from the pull request, so a pull request can't change the
|
|
251
|
+
rules it's checked against, where its code is sent, or the answers it's
|
|
252
|
+
judged by. New or changed conventions apply once they're merged. Run
|
|
253
|
+
judgelint with `--pr` on pull requests; a plain `judgelint` or `--base` run
|
|
254
|
+
uses the checked-out files as they are.
|
|
255
|
+
|
|
256
|
+
Even so, give the job only the model's API key. The pull request's code is
|
|
257
|
+
still what's being read, and the model can be argued with: a comment in the
|
|
258
|
+
code can sway its answer. judgelint is a reviewer, not a security gate.
|
|
259
|
+
|
|
260
|
+
## What gets sent
|
|
261
|
+
|
|
262
|
+
For each file a rule checks, the model gets the file's path and its whole
|
|
263
|
+
contents, numbered, with the spec's text and any `context:` files the rule
|
|
264
|
+
names. A directory rule sends every file in the directory. Nothing else on
|
|
265
|
+
your machine is read or sent:
|
|
266
|
+
|
|
267
|
+
- Only files inside the directory judgelint runs in, and none reached
|
|
268
|
+
through a link that leads out of it.
|
|
269
|
+
- In a git repository, only files git tracks or would add, never ignored
|
|
270
|
+
ones.
|
|
271
|
+
- No binary files, and nothing over 4 MB.
|
|
272
|
+
|
|
273
|
+
Requests go to the model's API over https, or plain http to a server on
|
|
274
|
+
your own machine. The API key goes only to its own provider's address: a
|
|
275
|
+
provider pointed somewhere else with `api_base` needs its own `api_key_env`.
|
|
276
|
+
|
|
239
277
|
## Configuration
|
|
240
278
|
|
|
241
279
|
judgelint runs without a config file. `.judgelint.yml` has four settings:
|
|
@@ -247,7 +285,11 @@ ignore: ["vendor/**"] # files no rule checks, and READMEs that aren't specs
|
|
|
247
285
|
max_cost_usd: 1.00 # refuse a run estimated to cost more, unless --yes
|
|
248
286
|
```
|
|
249
287
|
|
|
250
|
-
|
|
288
|
+
A model judgelint has no price for, like any model on OpenRouter, needs a
|
|
289
|
+
`price_per_million` (see below) before a run will spend money on it, or
|
|
290
|
+
`--yes`. A server on your own machine costs nothing.
|
|
291
|
+
|
|
292
|
+
Every run prints what it cost. Answers are cached in `.judgelint/cache.bin`,
|
|
251
293
|
so a file that hasn't changed costs nothing. Commit the cache to share it.
|
|
252
294
|
`judgelint --help` lists the flags.
|
|
253
295
|
|
|
@@ -269,23 +311,20 @@ For any other System One or Decisions endpoint, add a mapping to `models`:
|
|
|
269
311
|
models:
|
|
270
312
|
- api_base: https://gateway.example.com/${TEAM} # ${VAR} reads the environment
|
|
271
313
|
model: some-decider
|
|
272
|
-
api_key_env: GATEWAY_KEY
|
|
314
|
+
api_key_env: GATEWAY_KEY # sent only to this api_base
|
|
273
315
|
# path: /v1/systemone protocol: system_one|decisions auth: bearer|basic|none|header:<name>
|
|
274
316
|
# headers: {} provider_options: {} price_per_million: 0.04 batch_size: 32
|
|
275
317
|
```
|
|
276
318
|
|
|
277
319
|
## Building from source
|
|
278
320
|
|
|
279
|
-
judgelint is written in
|
|
280
|
-
[Spinel](https://github.com/matz/spinel).
|
|
321
|
+
judgelint is written in Rust. The end-to-end tests are in Ruby.
|
|
281
322
|
|
|
282
323
|
```sh
|
|
324
|
+
cargo build --release # builds target/release/judgelint
|
|
283
325
|
bundle install
|
|
284
|
-
bundle exec rake test
|
|
285
|
-
|
|
286
|
-
SPINEL=../spinel/bin/spinel bundle exec rake spinel # builds build/judgelint
|
|
287
|
-
SPINEL=../spinel/bin/spinel bundle exec rake test:spinel # runs the tests against the binary
|
|
288
|
-
bundle exec rake example # asks Jev about the demo app again
|
|
326
|
+
bundle exec rake test # runs the Rust tests, then the end-to-end tests against the binary
|
|
327
|
+
bundle exec rake example # asks Jev about the demo app again
|
|
289
328
|
```
|
|
290
329
|
|
|
291
330
|
## Credits
|
data/exe/judgelint
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
native = File.expand_path("../libexec/judgelint", __dir__)
|
|
9
|
-
exec(native, *ARGV) if File.executable?(native)
|
|
10
|
-
end
|
|
4
|
+
# The platform gems (judgelint-*-arm64-darwin and so on) carry the binary in
|
|
5
|
+
# libexec/. The plain gem, for every other platform, has none.
|
|
6
|
+
native = File.expand_path("../libexec/judgelint", __dir__)
|
|
7
|
+
exec(native, *ARGV) if File.executable?(native)
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
abort <<~TEXT
|
|
10
|
+
This judgelint gem has no binary for #{RUBY_PLATFORM}. The binaries are for
|
|
11
|
+
macOS and Linux on arm64 and x86_64. With Rust installed, build it instead:
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
cargo install --git https://github.com/jpcamara/judgelint
|
|
14
|
+
TEXT
|
data/libexec/judgelint
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: judgelint
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: aarch64-linux
|
|
6
6
|
authors:
|
|
7
7
|
- JP Camara
|
|
@@ -12,8 +12,8 @@ dependencies: []
|
|
|
12
12
|
description: |
|
|
13
13
|
judgelint checks code against conventions you write as bullets in a README.
|
|
14
14
|
It asks a decision model, such as TypeSafe's Jev, whether each file breaks
|
|
15
|
-
each bullet, and reports violations with line numbers.
|
|
16
|
-
|
|
15
|
+
each bullet, and reports violations with line numbers. The gem carries
|
|
16
|
+
its native binary for macOS and Linux.
|
|
17
17
|
email:
|
|
18
18
|
- johnpcamara@gmail.com
|
|
19
19
|
executables:
|
|
@@ -25,29 +25,6 @@ files:
|
|
|
25
25
|
- LICENSE
|
|
26
26
|
- README.md
|
|
27
27
|
- exe/judgelint
|
|
28
|
-
- lib/judgelint.rb
|
|
29
|
-
- lib/judgelint/cache.rb
|
|
30
|
-
- lib/judgelint/changes.rb
|
|
31
|
-
- lib/judgelint/cli.rb
|
|
32
|
-
- lib/judgelint/client.rb
|
|
33
|
-
- lib/judgelint/config.rb
|
|
34
|
-
- lib/judgelint/errors.rb
|
|
35
|
-
- lib/judgelint/glob.rb
|
|
36
|
-
- lib/judgelint/paint.rb
|
|
37
|
-
- lib/judgelint/pool.rb
|
|
38
|
-
- lib/judgelint/protocol.rb
|
|
39
|
-
- lib/judgelint/providers.rb
|
|
40
|
-
- lib/judgelint/question.rb
|
|
41
|
-
- lib/judgelint/reporter.rb
|
|
42
|
-
- lib/judgelint/rule.rb
|
|
43
|
-
- lib/judgelint/runner.rb
|
|
44
|
-
- lib/judgelint/scaffold.rb
|
|
45
|
-
- lib/judgelint/source.rb
|
|
46
|
-
- lib/judgelint/spec.rb
|
|
47
|
-
- lib/judgelint/usage.rb
|
|
48
|
-
- lib/judgelint/verdict.rb
|
|
49
|
-
- lib/judgelint/version.rb
|
|
50
|
-
- lib/rubygems_plugin.rb
|
|
51
28
|
- libexec/judgelint
|
|
52
29
|
homepage: https://github.com/jpcamara/judgelint
|
|
53
30
|
licenses:
|
data/lib/judgelint/cache.rb
DELETED
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Judgelint
|
|
4
|
-
# Stores each answer under a hash of everything that produced it: the state
|
|
5
|
-
# the model saw (path and numbered contents), the question asked of it, and
|
|
6
|
-
# the model. Changing any of them is a miss. Safe to share across threads.
|
|
7
|
-
#
|
|
8
|
-
# A cache file in the form #save writes stays on disk: loading it checks
|
|
9
|
-
# every entry and keeps its key and where it is, and a lookup finds the
|
|
10
|
-
# key by binary search and reads that entry back. Any other JSON object is
|
|
11
|
-
# read whole. New answers wait for #save in a scratch file beside the
|
|
12
|
-
# cache, already in the form it writes. A cache used again after it's saved
|
|
13
|
-
# reads its new file first.
|
|
14
|
-
class Cache
|
|
15
|
-
# A line that starts an entry, without its line ending: its key, then
|
|
16
|
-
# its value or the value's first line.
|
|
17
|
-
ENTRY = /\A "([0-9a-f]{64})": (.*)\z/
|
|
18
|
-
# Values in the plain form #save writes, which parse without being
|
|
19
|
-
# parsed: a number or literal, or a line of a hash of them with an ASCII
|
|
20
|
-
# name. Anything else is parsed to check it.
|
|
21
|
-
SCALAR = /\A(?:-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?|null|true|false)\z/
|
|
22
|
-
# Spinel's JSON parser outruns its regexps, where CRuby's parser makes
|
|
23
|
-
# more garbage than its regexps do, so only CRuby checks by pattern.
|
|
24
|
-
BY_PATTERN = RUBY_ENGINE != "spinel"
|
|
25
|
-
MEMBER = %r{\A "(?:[\x20\x21\x23-\x5b\x5d-\x7e]|\\["\\/bfnrt])*": (?:-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?|null|true|false),?\r?\n\z}
|
|
26
|
-
KEY_SIZE = 64
|
|
27
|
-
# Where a value starts in its entry's first line.
|
|
28
|
-
VALUE_AT = 70
|
|
29
|
-
# A value's place in a file is kept as one Integer: its offset, shifted
|
|
30
|
-
# past its length.
|
|
31
|
-
SPAN_BITS = 32
|
|
32
|
-
|
|
33
|
-
def initialize(path)
|
|
34
|
-
@path = path
|
|
35
|
-
@keys = +"" # the file's keys in order, end to end
|
|
36
|
-
@places = [] # the place of each key's value in the file
|
|
37
|
-
@entries = {} # every answer from a file read whole, or stored without a file
|
|
38
|
-
@stored_keys = +"" # the keys of answers stored this run, end to end, in the order stored
|
|
39
|
-
@stored_places = [] # the place of each in the scratch file
|
|
40
|
-
@dirty = false
|
|
41
|
-
@saved = false
|
|
42
|
-
@lock = Mutex.new
|
|
43
|
-
load_entries
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def self.key(question_digest, state_digest, model_label)
|
|
47
|
-
Digest::SHA256.hexdigest([question_digest, state_digest, model_label].join(":"))
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def fetch(key)
|
|
51
|
-
@lock.synchronize do
|
|
52
|
-
reload if @saved
|
|
53
|
-
if (stored = stored(key))
|
|
54
|
-
read(@scratch, @stored_places[stored])
|
|
55
|
-
elsif (found = find(key))
|
|
56
|
-
read(@file, @places[found])
|
|
57
|
-
else
|
|
58
|
-
@entries[key]
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# Makes room for about +count+ answers to be stored, so their keys don't
|
|
64
|
-
# grow a piece at a time.
|
|
65
|
-
def reserve(count)
|
|
66
|
-
@lock.synchronize do
|
|
67
|
-
return unless @path
|
|
68
|
-
|
|
69
|
-
reload if @saved
|
|
70
|
-
@stored_keys = String.new(capacity: count * KEY_SIZE) << @stored_keys if @stored_keys.bytesize < count * KEY_SIZE
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def store(key, yes_probability)
|
|
75
|
-
@lock.synchronize do
|
|
76
|
-
reload if @saved
|
|
77
|
-
@dirty = true
|
|
78
|
-
if @path
|
|
79
|
-
text = indented(yes_probability)
|
|
80
|
-
@scratch ||= scratch
|
|
81
|
-
@stored_keys << key
|
|
82
|
-
@stored_places << place(@scratch_size, text.bytesize)
|
|
83
|
-
@scratch.write(text)
|
|
84
|
-
@scratch.flush
|
|
85
|
-
@scratch_size += text.bytesize
|
|
86
|
-
else
|
|
87
|
-
@entries[key] = yes_probability
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
# Writes every entry in key order, as JSON.pretty_generate does, one at a
|
|
93
|
-
# time into a new file that then replaces the old one.
|
|
94
|
-
def save
|
|
95
|
-
@lock.synchronize do
|
|
96
|
-
return unless @path && @dirty
|
|
97
|
-
|
|
98
|
-
FileUtils.mkdir_p(File.dirname(@path))
|
|
99
|
-
temp = "#{@path}.#{Process.pid}.tmp"
|
|
100
|
-
File.open(temp, "w") { |out| write(out) }
|
|
101
|
-
close
|
|
102
|
-
File.rename(temp, @path)
|
|
103
|
-
@dirty = false
|
|
104
|
-
@saved = true
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
private
|
|
109
|
-
|
|
110
|
-
# The index of +key+ among the file's keys, or nil.
|
|
111
|
-
def find(key)
|
|
112
|
-
low = 0
|
|
113
|
-
high = @places.size - 1
|
|
114
|
-
while low <= high
|
|
115
|
-
middle = (low + high) / 2
|
|
116
|
-
other = @keys.byteslice(middle * KEY_SIZE, KEY_SIZE)
|
|
117
|
-
return middle if other == key
|
|
118
|
-
|
|
119
|
-
other < key ? low = middle + 1 : high = middle - 1
|
|
120
|
-
end
|
|
121
|
-
nil
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
# The latest answer stored this run under +key+, or nil. A run looks its
|
|
125
|
-
# answers up before it stores any, so there are rarely any to look at.
|
|
126
|
-
def stored(key)
|
|
127
|
-
index = @stored_places.size - 1
|
|
128
|
-
while index >= 0
|
|
129
|
-
return index if @stored_keys.byteslice(index * KEY_SIZE, KEY_SIZE) == key
|
|
130
|
-
|
|
131
|
-
index -= 1
|
|
132
|
-
end
|
|
133
|
-
nil
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
def read(file, at)
|
|
137
|
-
JSON.parse(raw(file, at))
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def raw(file, at)
|
|
141
|
-
file.pread(at & ((1 << SPAN_BITS) - 1), at >> SPAN_BITS)
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def place(offset, length)
|
|
145
|
-
(offset << SPAN_BITS) | length
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
# Deleted as soon as it's open where the system allows that, so it goes
|
|
149
|
-
# away with the process; elsewhere, once the cache is saved.
|
|
150
|
-
def scratch
|
|
151
|
-
FileUtils.mkdir_p(File.dirname(@path))
|
|
152
|
-
path = "#{@path}.#{Process.pid}.answers"
|
|
153
|
-
file = File.open(path, "w+b")
|
|
154
|
-
begin
|
|
155
|
-
File.delete(path)
|
|
156
|
-
rescue SystemCallError
|
|
157
|
-
@scratch_path = path
|
|
158
|
-
end
|
|
159
|
-
@scratch_size = 0
|
|
160
|
-
file
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
def reload
|
|
164
|
-
@saved = false
|
|
165
|
-
@keys = +""
|
|
166
|
-
@places = []
|
|
167
|
-
@entries = {}
|
|
168
|
-
@stored_keys = +""
|
|
169
|
-
@stored_places = []
|
|
170
|
-
@scratch = nil
|
|
171
|
-
@scratch_path = nil
|
|
172
|
-
load_entries
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
# The file can't be replaced while it's open everywhere.
|
|
176
|
-
def close
|
|
177
|
-
@file&.close
|
|
178
|
-
@scratch&.close
|
|
179
|
-
File.delete(@scratch_path) if @scratch_path
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
# Merges the file's entries, or those read whole, with the answers stored
|
|
183
|
-
# this run, which replace any with the same key.
|
|
184
|
-
def write(out)
|
|
185
|
-
whole = @entries.keys.sort
|
|
186
|
-
kept = whole.empty? ? @places.size : whole.size
|
|
187
|
-
count = 0
|
|
188
|
-
i = 0
|
|
189
|
-
stored_buckets.each do |bucket|
|
|
190
|
-
keys = bucket.map { |index| @stored_keys.byteslice(index * KEY_SIZE, KEY_SIZE) }
|
|
191
|
-
latest(keys).each do |n|
|
|
192
|
-
key = keys[n]
|
|
193
|
-
while i < kept && (mine = kept_key(whole, i)) < key
|
|
194
|
-
count = entry(out, count, mine, kept_text(whole, i))
|
|
195
|
-
i += 1
|
|
196
|
-
end
|
|
197
|
-
i += 1 if i < kept && kept_key(whole, i) == key
|
|
198
|
-
count = entry(out, count, key, raw(@scratch, @stored_places[bucket[n]]))
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
while i < kept
|
|
202
|
-
count = entry(out, count, kept_key(whole, i), kept_text(whole, i))
|
|
203
|
-
i += 1
|
|
204
|
-
end
|
|
205
|
-
out.write(count.zero? ? "{}\n" : "\n}\n")
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
# +text+ is the value, indented to sit in the file's object.
|
|
209
|
-
def entry(out, count, key, text)
|
|
210
|
-
out.write(count.zero? ? "{\n " : ",\n ")
|
|
211
|
-
out.write(JSON.generate(key))
|
|
212
|
-
out.write(": ")
|
|
213
|
-
out.write(text)
|
|
214
|
-
count + 1
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
def indented(value)
|
|
218
|
-
JSON.pretty_generate(value).gsub("\n", "\n ")
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
def kept_key(whole, index)
|
|
222
|
-
whole.empty? ? @keys.byteslice(index * KEY_SIZE, KEY_SIZE) : whole[index]
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
def kept_text(whole, index)
|
|
226
|
-
indented(whole.empty? ? read(@file, @places[index]) : @entries[whole[index]])
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
# The answers stored this run, by the first two hex digits of their keys:
|
|
230
|
-
# in key order a bucket at a time, so only one bucket's keys are out at
|
|
231
|
-
# once.
|
|
232
|
-
def stored_buckets
|
|
233
|
-
buckets = Array.new(256) { [] }
|
|
234
|
-
@stored_places.size.times do |index|
|
|
235
|
-
at = index * KEY_SIZE
|
|
236
|
-
buckets[(digit(@stored_keys.getbyte(at)) << 4) | digit(@stored_keys.getbyte(at + 1))] << index
|
|
237
|
-
end
|
|
238
|
-
buckets
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
def digit(byte)
|
|
242
|
-
byte < 97 ? byte - 48 : byte - 87
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
# The indexes of +keys+ in key order, keeping the latest of any stored twice.
|
|
246
|
-
def latest(keys)
|
|
247
|
-
found = []
|
|
248
|
-
(0...keys.size).sort_by { |index| keys[index] }.each do |index|
|
|
249
|
-
if !found.empty? && keys[found.last] == keys[index]
|
|
250
|
-
found[-1] = index if index > found.last
|
|
251
|
-
else
|
|
252
|
-
found << index
|
|
253
|
-
end
|
|
254
|
-
end
|
|
255
|
-
found
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
def load_entries
|
|
259
|
-
return unless @path && File.exist?(@path)
|
|
260
|
-
|
|
261
|
-
@file = File.open(@path, "rb")
|
|
262
|
-
return if index
|
|
263
|
-
|
|
264
|
-
@keys = +""
|
|
265
|
-
@places = []
|
|
266
|
-
data = JSON.parse(File.read(@path))
|
|
267
|
-
raise ConfigError, "#{@path} isn't a judgelint cache; delete it to start over" unless data.is_a?(Hash)
|
|
268
|
-
|
|
269
|
-
@entries = data
|
|
270
|
-
rescue JSON::ParserError
|
|
271
|
-
raise ConfigError, "#{@path} isn't valid JSON; delete it to start over"
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
# Indexes a file in the form #save writes, with its keys in order,
|
|
275
|
-
# checking that each value parses. Lines may end in CRLF, as #save writes
|
|
276
|
-
# them on Windows. False for anything else.
|
|
277
|
-
def index
|
|
278
|
-
offset = 0
|
|
279
|
-
last = nil # the latest key
|
|
280
|
-
open = false # inside a value that spans lines
|
|
281
|
-
start = 0
|
|
282
|
-
plain = false # the open value's lines are all plain so far
|
|
283
|
-
comma = true # the open value's last line ended in a comma
|
|
284
|
-
ended = false # read the entry without a comma
|
|
285
|
-
closed = false # read the final brace
|
|
286
|
-
@file.each_line do |line|
|
|
287
|
-
return false if closed
|
|
288
|
-
|
|
289
|
-
if open && line.start_with?(" ")
|
|
290
|
-
plain &&= BY_PATTERN && comma && line.match?(MEMBER)
|
|
291
|
-
comma = line.end_with?(",\n", ",\r\n")
|
|
292
|
-
offset += line.bytesize
|
|
293
|
-
next
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
bare = line.chomp
|
|
297
|
-
if offset.zero?
|
|
298
|
-
return false unless bare == "{" || bare == "{}"
|
|
299
|
-
|
|
300
|
-
closed = bare == "{}"
|
|
301
|
-
elsif open
|
|
302
|
-
return false unless bare == " }" || bare == " },"
|
|
303
|
-
return false unless indexed(last, start, offset + 3 - start, plain && !comma)
|
|
304
|
-
|
|
305
|
-
open = false
|
|
306
|
-
ended = bare == " }"
|
|
307
|
-
elsif ended
|
|
308
|
-
return false unless bare == "}"
|
|
309
|
-
|
|
310
|
-
closed = true
|
|
311
|
-
else
|
|
312
|
-
match = ENTRY.match(bare)
|
|
313
|
-
return false unless match && (last.nil? || last < match[1])
|
|
314
|
-
|
|
315
|
-
last = match[1]
|
|
316
|
-
rest = match[2]
|
|
317
|
-
start = offset + VALUE_AT
|
|
318
|
-
if rest == "{"
|
|
319
|
-
open = true
|
|
320
|
-
plain = true
|
|
321
|
-
comma = true
|
|
322
|
-
else
|
|
323
|
-
ended = !rest.end_with?(",")
|
|
324
|
-
value = ended ? rest : rest.delete_suffix(",")
|
|
325
|
-
return false unless indexed(last, start, value.bytesize, BY_PATTERN && value.match?(SCALAR), value)
|
|
326
|
-
end
|
|
327
|
-
end
|
|
328
|
-
offset += line.bytesize
|
|
329
|
-
end
|
|
330
|
-
closed
|
|
331
|
-
end
|
|
332
|
-
|
|
333
|
-
# Keeps +key+'s place, once its value is known to parse. +text+ is the
|
|
334
|
-
# value when it's at hand.
|
|
335
|
-
def indexed(key, start, length, plain, text = nil)
|
|
336
|
-
JSON.parse(text || @file.pread(length, start)) unless plain
|
|
337
|
-
@keys << key
|
|
338
|
-
@places << place(start, length)
|
|
339
|
-
true
|
|
340
|
-
rescue JSON::ParserError
|
|
341
|
-
false
|
|
342
|
-
end
|
|
343
|
-
end
|
|
344
|
-
end
|
data/lib/judgelint/changes.rb
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Judgelint
|
|
4
|
-
# The lines a change touched, from git: everything since the merge base with
|
|
5
|
-
# a ref, uncommitted work included. Old code outside the change isn't asked
|
|
6
|
-
# about, so it can't block new work.
|
|
7
|
-
module Changes
|
|
8
|
-
# A branch, tag, or commit (HEAD~1 too), and nothing git could read as an
|
|
9
|
-
# option or a range.
|
|
10
|
-
REF = %r{\A[A-Za-z0-9][A-Za-z0-9._/~^-]*\z}
|
|
11
|
-
HUNK = /\A@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/
|
|
12
|
-
|
|
13
|
-
# Returns {path => [changed line numbers]}, or :all for a new file.
|
|
14
|
-
def self.since(ref)
|
|
15
|
-
check_ref(ref)
|
|
16
|
-
base = git("merge-base", ref, "HEAD").strip
|
|
17
|
-
changed = parse_diff(git("-c", "core.quotePath=false", "diff", "-U0", "--no-color", "--no-ext-diff",
|
|
18
|
-
"--relative", "--diff-filter=d", base))
|
|
19
|
-
git("ls-files", "--others", "--exclude-standard").lines.each { |path| changed[path.chomp] = :all }
|
|
20
|
-
changed
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# CI variables that name a pull request's base branch.
|
|
24
|
-
BASE_BRANCH_VARIABLES = %w[
|
|
25
|
-
JUDGELINT_BASE_BRANCH GITHUB_BASE_REF CI_MERGE_REQUEST_TARGET_BRANCH_NAME
|
|
26
|
-
BUILDKITE_PULL_REQUEST_BASE_BRANCH BITBUCKET_PR_DESTINATION_BRANCH SYSTEM_PULLREQUEST_TARGETBRANCH
|
|
27
|
-
].freeze
|
|
28
|
-
|
|
29
|
-
# The pull request's base branch, fetched, as origin/<branch>: from
|
|
30
|
-
# JUDGELINT_BASE_BRANCH, then GitHub Actions, GitLab, Buildkite, Bitbucket,
|
|
31
|
-
# or Azure Pipelines, then the gh CLI.
|
|
32
|
-
def self.pr_base
|
|
33
|
-
branch = pr_branch
|
|
34
|
-
raise ConfigError, "Couldn't find the pull request's base branch" if branch.empty?
|
|
35
|
-
|
|
36
|
-
check_ref(branch)
|
|
37
|
-
git("fetch", "--no-tags", "--quiet", "origin", branch)
|
|
38
|
-
"origin/#{branch}"
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def self.pr_branch
|
|
42
|
-
BASE_BRANCH_VARIABLES.each do |name|
|
|
43
|
-
# Buildkite sets "false" outside a pull request; Azure names a full ref.
|
|
44
|
-
branch = ENV.fetch(name, "").delete_prefix("refs/heads/")
|
|
45
|
-
return branch unless branch.empty? || branch == "false"
|
|
46
|
-
end
|
|
47
|
-
command("gh", "pr", "view", "--json", "baseRefName", "-q", ".baseRefName").strip
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def self.parse_diff(diff)
|
|
51
|
-
changed = {}
|
|
52
|
-
path = nil
|
|
53
|
-
diff.each_line do |line|
|
|
54
|
-
if line.start_with?("+++ ")
|
|
55
|
-
target = line.chomp.delete_prefix("+++ ").delete_suffix("\t")
|
|
56
|
-
path = target == "/dev/null" ? nil : target.delete_prefix("b/")
|
|
57
|
-
elsif path && (hunk = HUNK.match(line))
|
|
58
|
-
start = hunk[1].to_i
|
|
59
|
-
count = hunk[2] ? hunk[2].to_i : 1
|
|
60
|
-
# A pure deletion marks the line above the gap, so it's still judged.
|
|
61
|
-
lines = count.zero? ? [[start, 1].max] : (start...(start + count)).to_a
|
|
62
|
-
(changed[path] ||= []).concat(lines)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
changed
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def self.check_ref(ref)
|
|
69
|
-
return if REF.match?(ref) && !ref.include?("..")
|
|
70
|
-
|
|
71
|
-
raise ConfigError, "Not a usable git ref: #{ref}"
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def self.git(*args)
|
|
75
|
-
command("git", *args)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def self.command(*args)
|
|
79
|
-
out, err, status = Open3.capture3(*args)
|
|
80
|
-
raise ConfigError, "#{args.first(3).join(' ')} failed: #{err.strip.lines.first.to_s.strip}" unless status.success?
|
|
81
|
-
|
|
82
|
-
out
|
|
83
|
-
rescue SystemCallError => e
|
|
84
|
-
raise ConfigError, "Couldn't run #{args.first}: #{e.message}"
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|