rspec-osc7501 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5789a92d347d7a152a9b2ce9a2edd188a21d6209beb9f41247f1a0713598233
4
- data.tar.gz: 7ed3f5e657885323cb1381ecdb6202f299dd1f7db5f7239120329b9cecdb9c29
3
+ metadata.gz: 5768212549d6cfe8f1db7e61e6e9ccb8b930c51536f00c3dd25c1aa7788d11fc
4
+ data.tar.gz: a93974d3e6cc872aca1845d9590e1945773d29020c3774277ba5023175c1951f
5
5
  SHA512:
6
- metadata.gz: 1934634e2afade69128ade89e9d1aa8a27eafa1449142c5b3807411e9af5eec7b8e6b538c13fd3e2fb70a63b773719a76cc85521688761919aece4dac57699b8
7
- data.tar.gz: 1b0a02f82acf691eb1e36dc9f6c44f7078daeef4faff113da8c1bc18d210493cc745f1131359dc2c4018929364a82d2a997ee89be43333d5b77f98f485c7d84f
6
+ metadata.gz: 8193fb2359fc8227db3646ebe4d3b8e20810bf3ba3f8adf379fb2dd634a6ecea6729ed7dbc49c7e4772a377175760a61169a1718516c603f3f83c87da6dc8393
7
+ data.tar.gz: f484ce546596745aff7671d4dd474405197fbc36d0bfaaefe0fa09f30f8bcfff989c7216881b91c89f6c0f564f7c3e053a74bf82713c73882ec2c00ef9737605
data/ACCESSIBILITY.md ADDED
@@ -0,0 +1,36 @@
1
+ # Accessibility
2
+
3
+ Read test results without relying on terminal status indicators. Use
4
+ rspec-osc7501 alongside an RSpec text formatter so failures and
5
+ the suite summary remain available as text.
6
+
7
+ ## Plain text output
8
+
9
+ Run this for example descriptions and results without color or terminal status:
10
+
11
+ ```sh
12
+ RSPEC_OSC7501=off bundle exec rspec --format documentation --no-color
13
+ ```
14
+
15
+ `--no-color` disables RSpec's text colors. `RSPEC_OSC7501=off` disables this
16
+ gem's status records, even when your RSpec configuration selects the formatter.
17
+
18
+ By default, the formatter sends no status records to pipes, files, or terminals
19
+ with `TERM=dumb`. `RSPEC_OSC7501=force` overrides those defaults.
20
+
21
+ ## Environments and limits
22
+
23
+ The gem supports MRI Ruby 3.3 or newer and RSpec Core 3.12 through 3.x.
24
+ Terminal status requires an OSC 7501-capable terminal. The formatter checks
25
+ for a TTY and honors `TERM=dumb` but does not detect OSC support.
26
+
27
+ Your terminal controls how it displays or announces status. I have not tested
28
+ the status display with screen readers. The command above gives you plain text,
29
+ but your screen reader may need other settings.
30
+
31
+ ## Report a barrier
32
+
33
+ Open an [issue](https://github.com/cosgroveb/rspec-osc7501/issues) describing what
34
+ you tried, what prevented you from using it, and what would help. Include your
35
+ terminal, operating system, and assistive technology versions when relevant.
36
+ You do not need to disclose a disability or other medical information.
data/CHANGELOG.md CHANGED
@@ -2,5 +2,29 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.1.2 - 2026-11-09
6
+
7
+ - Bump actions/checkout from 4.4.0 to 7.0.1 ([c19db3a](https://github.com/cosgroveb/rspec-osc7501/commit/c19db3a1a8c5bb41ab4db2eb0bc8740ce0a66bd0))
8
+ - Enforce Ruby and workflow quality checks ([c0e9320](https://github.com/cosgroveb/rspec-osc7501/commit/c0e9320b9fc75dd03929fd5c2d5f2726b8ad22b3))
9
+ - Exercise sanitizer boundaries and installed gems ([b45d454](https://github.com/cosgroveb/rspec-osc7501/commit/b45d454be50ab1ad50bef32c3079b56a4f6dfcd6))
10
+ - Allow releases through protected main ([89c96ea](https://github.com/cosgroveb/rspec-osc7501/commit/89c96ea8632d68e6f4d3606cd89bff502dab0d11))
11
+ - Randomize specs and await release visibility ([09bf9ca](https://github.com/cosgroveb/rspec-osc7501/commit/09bf9ca29d03f9e40fa853952b804e1353384ea1))
12
+ - Simplify release polling and its tests ([db1c2a9](https://github.com/cosgroveb/rspec-osc7501/commit/db1c2a9eb2210890c628c6bf5a0e069f12cabdea))
13
+ - Add community policies and contribution templates ([950295c](https://github.com/cosgroveb/rspec-osc7501/commit/950295cf24395f8883d43c9b30f977f579116da1))
14
+ - Clarify responsibility for AI-assisted work ([7d7f1b9](https://github.com/cosgroveb/rspec-osc7501/commit/7d7f1b93df6e13f70e764ce80041e802431fc739))
15
+ - Clarify accessibility controls and limits ([e5f34c1](https://github.com/cosgroveb/rspec-osc7501/commit/e5f34c10a7f326dbc972c170b477a0265ec7cea2))
16
+ - Clarify docs and merge preferences ([81256da](https://github.com/cosgroveb/rspec-osc7501/commit/81256daa9297c3bb29037c1d8ca01ed0f2d42f13))
17
+ - Honor dumb terminals in automatic status mode ([f45a078](https://github.com/cosgroveb/rspec-osc7501/commit/f45a078583a00756089fee59caebae1531c9f305))
18
+ - Clarify release and formatter documentation ([3d13c4b](https://github.com/cosgroveb/rspec-osc7501/commit/3d13c4ba8fe90aa5bf358b906f8108d5d3a93914))
19
+
20
+ ## 0.1.1 - 2026-11-08
21
+
22
+ - Fix formatter outcomes and stream handling ([3454f8a](https://github.com/cosgroveb/rspec-osc7501/commit/3454f8a63e05e8955ac42038d494d90cfaec9429))
23
+ - Bound formatter text sanitization work ([5d2fc9f](https://github.com/cosgroveb/rspec-osc7501/commit/5d2fc9f9c5465e3086d3673e699e03fd3d8f5c86))
24
+ - Automate tested RubyGems releases ([86f87f3](https://github.com/cosgroveb/rspec-osc7501/commit/86f87f3faadfb313377d1ece592e12d45f228632))
25
+ - Bound CI runtime and cancel superseded checks ([0d4660d](https://github.com/cosgroveb/rspec-osc7501/commit/0d4660d2d6b90a4208fc8f0faeac8e50e5c3796c))
26
+
27
+ ## 0.1.0 - 2026-11-07
28
+
5
29
  - Add an opt-in OSC 7501 formatter for RSpec suite progress and outcomes.
6
30
  - Support TTY detection, explicit output capture, and a configurable suite title.
@@ -0,0 +1,68 @@
1
+ # Code of conduct
2
+
3
+ Everyone who participates in good faith is welcome in rspec-osc7501. Treat
4
+ people with respect, regardless of race, ethnicity, caste, color, age, physical
5
+ characteristics, neurodiversity, disability, sex, gender identity or expression,
6
+ sexual orientation, language, philosophy, religion, national or social origin,
7
+ income, education, or other status.
8
+
9
+ ## Working together
10
+
11
+ Respect the project's purpose and other people's time. Discuss ideas without
12
+ attacking people. Make room for different viewpoints and experiences. Give and
13
+ accept constructive feedback. Account for differences in language, culture,
14
+ and communication when interpreting what someone says.
15
+
16
+ Take responsibility for what you submit, including code, reports, and comments
17
+ produced with AI assistance. Review it before sharing, make sure you understand
18
+ it, and respond to questions and corrections. Respect the time others spend
19
+ reviewing your work. Take responsibility for repairing harm you cause.
20
+
21
+ Do not:
22
+
23
+ - Harass people, ignore a request to stop, or violate stated boundaries.
24
+ - Make personal attacks, discriminate, or stereotype people by identity.
25
+ - Make unwanted sexual comments or advances.
26
+ - Share or use someone's private information without permission.
27
+ - Threaten, encourage, or cause violence or other harm.
28
+ - Impersonate someone or evade moderation with another identity.
29
+ - Contribute someone else's work without credit.
30
+ - Post unrelated advertising or present harmful content without appropriate
31
+ context and care.
32
+
33
+ Threatening or encouraging these behaviors also violates this policy. Other
34
+ behavior that threatens the community's well-being may warrant moderation.
35
+ Disagreement alone is not a conduct violation.
36
+
37
+ ## Reporting and enforcement
38
+
39
+ Report concerns privately to Brian Cosgrove at
40
+ [cosgroveb@gmail.com](mailto:cosgroveb@gmail.com). Include what happened and any
41
+ relevant links or messages. Do not post private reports in public issues.
42
+
43
+ I review and investigate reports, hear from the people involved as needed, and
44
+ prioritize safety and confidentiality. I share report details only as needed
45
+ to investigate and respond. I handle enforcement privately and discuss any
46
+ public resolution with the people involved. I respond as availability permits,
47
+ without a guaranteed deadline.
48
+
49
+ Depending on severity and repetition, I may issue a warning, remove content,
50
+ restrict participation, or impose a temporary or permanent ban. Serious
51
+ violations may lead to an immediate ban. Where continued participation is
52
+ appropriate, I explain what needs to change and any conditions for returning.
53
+ These rules apply to maintainers as well as other participants.
54
+
55
+ ## Scope
56
+
57
+ This policy covers project spaces and anyone officially representing the
58
+ project elsewhere, including through project accounts or at events.
59
+
60
+ ## Attribution
61
+
62
+ Adapted from [Contributor Covenant 3.0](https://www.contributor-covenant.org/version/3/0/code_of_conduct/),
63
+ stewarded by the Organization for Ethical Source. This adaptation shortens the
64
+ wording and uses a maintainer-led reporting and enforcement process.
65
+
66
+ This document is licensed under
67
+ [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/).
68
+ The software remains licensed under [Apache License 2.0](LICENSE).
data/CONTRIBUTING.md CHANGED
@@ -1,12 +1,32 @@
1
1
  # Contributing
2
2
 
3
- Use MRI Ruby 3.3 or newer. Install dependencies and run specs:
3
+ Follow the [code of conduct](CODE_OF_CONDUCT.md). Report vulnerabilities through
4
+ the private channel in [SECURITY.md](SECURITY.md).
5
+
6
+ AI-assisted contributions are welcome. Before requesting review, understand
7
+ the changes, run relevant checks, and verify claims in code, documentation,
8
+ and reports. State what you tested and what remains uncertain. Be prepared to
9
+ explain your choices and address feedback. When using an agent to help answer
10
+ a reviewer, check the answer and send only what is relevant.
11
+
12
+ Use MRI Ruby 3.3 or newer. Install actionlint 1.7.12 on your PATH, then run all checks:
4
13
 
5
14
  ```sh
6
15
  bundle install
7
- bundle exec rake spec
16
+ bundle exec rake
8
17
  ```
9
18
 
19
+ The default task runs RuboCop with rubocop-rspec, bundler-audit, actionlint,
20
+ specs, installed-gem smoke tests and RDoc. Run `bundle exec rake lint`, `audit`, `workflows`,
21
+ or `spec` for individual checks. Keep RuboCop's default rules and fix violations
22
+ without adding exclusions or a TODO baseline. Dependency auditing checks the
23
+ lockfile generated by `bundle install`. Keep that lockfile out of commits.
24
+
25
+ Specs run in random order and report their seed. Reproduce an ordering failure
26
+ with `bundle exec rspec --seed <seed>` and narrow it with
27
+ `bundle exec rspec --seed <seed> --bisect`. Generated subprocess fixtures keep a
28
+ defined order because their interrupt and fail-fast cases depend on sequence.
29
+
10
30
  Keep runtime dependencies limited to `rspec-core`. Cover formatter behavior with
11
31
  specs and lifecycle changes with real RSpec subprocesses. Check RSpec 3.12 and
12
32
  3.13 when changing early-stop detection.
@@ -15,11 +35,55 @@ Build the gem and documentation:
15
35
 
16
36
  ```sh
17
37
  bundle exec rake package
38
+ bundle exec rake smoke
18
39
  bundle exec rake rdoc
19
40
  ```
20
41
 
21
- The package is `pkg/rspec-osc7501-0.1.0.gem`. Open `tmp/rdoc/index.html` to check
42
+ The package is `pkg/rspec-osc7501-<version>.gem`. Open `tmp/rdoc/index.html` to check
22
43
  rendered documentation. Keep generated files out of commits.
44
+ The smoke task builds and installs the gem in a temporary directory, then checks
45
+ passing and failing suites without loading the checkout's library.
46
+
47
+ Update usage or behavior documentation for user-visible changes. Write commit
48
+ subjects that describe the change, because release notes use those subjects.
49
+ Do not maintain `Unreleased` entries by hand. Preserve the Apache-2.0 license text.
50
+
51
+ ## Release
52
+
53
+ Release the reviewed commits on remote `main`. Replace `NEW_VERSION` with a
54
+ stable version greater than the current release:
55
+
56
+ ```sh
57
+ gh workflow run release.yml --ref main -f version=NEW_VERSION
58
+ ```
59
+
60
+ The workflow captures `main`, updates `VERSION`, and generates CHANGELOG bullets
61
+ from non-merge commit subjects since the previous release tag. It preserves
62
+ older changelog sections and uses the same notes for the GitHub Release.
63
+ Versions must use `major.minor.patch` without a `v` prefix or prerelease suffix.
64
+ A new version must exceed the current version and include new commits.
65
+
66
+ The full CI matrix tests the prepared release commit before the workflow pushes
67
+ it and its tag together. If `main` advances during testing, the workflow stops.
68
+ After the push, it publishes to RubyGems, then creates the GitHub Release. No
69
+ intermediate approval is required.
70
+
71
+ If a release fails, inspect its logs and rerun the same version. If its tag
72
+ already exists, the workflow tests and resumes that tagged release instead of
73
+ releasing newer commits on `main`.
74
+
75
+ ### One-time publishing setup
76
+
77
+ On the gem's RubyGems page, configure a Trusted Publisher with owner `cosgroveb`,
78
+ repository `rspec-osc7501`, and workflow `release.yml`. Leave the environment
79
+ blank. The workflow uses short-lived OIDC credentials, with no RubyGems token
80
+ stored in GitHub secrets. Repository Actions permissions must permit the
81
+ workflow's `contents: write` and `id-token: write` requests.
23
82
 
24
- Update usage or behavior documentation for user-visible changes and add a brief
25
- entry under `Unreleased` in `CHANGELOG.md`. Preserve the Apache-2.0 license text.
83
+ Store a dedicated write-enabled repository deploy key as the Actions secret
84
+ `RELEASE_DEPLOY_KEY`. Only the publish job uses it to push the tested commit
85
+ and tag. Require PRs and CI checks in a separate ruleset with deploy-key bypass,
86
+ and keep deletion and force-push protection in a ruleset without bypasses.
87
+ GitHub applies this bypass to all repository deploy keys, so additional write
88
+ deploy keys would receive the same access. GitHub API calls still use the
89
+ workflow token, and RubyGems still uses OIDC.
data/README.md CHANGED
@@ -2,20 +2,18 @@
2
2
 
3
3
  Report RSpec suite activity, progress and results to terminals that support
4
4
  [OSC 7501](https://www.superlogical.com/rex/docs/build/program-status).
5
- Use the formatter alongside RSpec’s progress or documentation formatter.
5
+ Use the formatter alongside RSpec's progress or documentation formatter.
6
6
 
7
7
  Requires MRI Ruby 3.3 or newer and `rspec-core >= 3.12, < 4`.
8
8
 
9
9
  ## Install
10
10
 
11
- This gem is unreleased. Add the source branch to your Gemfile:
11
+ Add the gem to your Gemfile:
12
12
 
13
13
  ```ruby
14
14
  group :test do
15
15
  gem "rspec"
16
- gem "rspec-osc7501",
17
- git: "https://github.com/cosgroveb/rspec-osc7501",
18
- branch: "feature/osc7501-formatter"
16
+ gem "rspec-osc7501", "~> 0.1"
19
17
  end
20
18
  ```
21
19
 
@@ -30,7 +28,7 @@ bundle exec rspec --require rspec/osc7501 \
30
28
  --format progress --format RSpec::OSC7501::Formatter
31
29
  ```
32
30
 
33
- Keep `--format progress` to retain RSpec’s dots, failures and summary. The OSC
31
+ Keep `--format progress` to see RSpec's dots, failures and summary. The OSC
34
32
  formatter reports completed examples and the final suite result through terminal
35
33
  status records. Requiring `rspec/osc7501` registers the formatter without selecting
36
34
  it.
@@ -50,8 +48,8 @@ with a `state=done` or `state=error` record.
50
48
 
51
49
  | Environment variable | Values | Default |
52
50
  | --- | --- | --- |
53
- | `RSPEC_OSC7501` | `auto` emits to a TTY, `off` disables output, `force` permits redirected output | `auto` |
54
- | `RSPEC_OSC7501_TITLE` | Title for the suite’s status records | `RSpec` |
51
+ | `RSPEC_OSC7501` | `auto` emits to a TTY unless `TERM=dumb`, `off` disables output, `force` overrides both checks | `auto` |
52
+ | `RSPEC_OSC7501_TITLE` | Title for the suite's status records | `RSpec` |
55
53
 
56
54
  The formatter uses the output stream RSpec assigns, including `--out`. Default
57
55
  mode emits nothing to redirected streams. Use one reporting RSpec process per
@@ -66,6 +64,9 @@ that bypasses formatter callbacks can leave the last status in place. See
66
64
  - [Usage recipes](doc/usage.rdoc): persistent configuration and output routing.
67
65
  - [Behavior and reference](doc/behavior.rdoc): progress, terminal states and limits.
68
66
  - [Contributing](CONTRIBUTING.md): development and verification commands.
67
+ - [Accessibility](ACCESSIBILITY.md): text output and reporting barriers.
68
+ - [Security policy](SECURITY.md): supported releases and private reporting.
69
+ - [Code of conduct](CODE_OF_CONDUCT.md): participation and conduct reports.
69
70
  - [Changelog](CHANGELOG.md).
70
71
 
71
72
  Licensed under [Apache License 2.0](LICENSE).
data/SECURITY.md ADDED
@@ -0,0 +1,22 @@
1
+ # Security policy
2
+
3
+ ## Supported versions
4
+
5
+ I provide security fixes for the latest released version of rspec-osc7501.
6
+ Upgrade to the latest release before checking whether a problem still occurs.
7
+ Older releases do not receive security backports.
8
+
9
+ ## Report a vulnerability
10
+
11
+ Use [GitHub private vulnerability reporting](https://github.com/cosgroveb/rspec-osc7501/security/advisories/new).
12
+ Do not disclose vulnerabilities in public issues or pull requests.
13
+
14
+ Include the affected gem, Ruby, and RSpec versions, steps or a small example
15
+ that reproduces the problem, and the impact. Include terminal and tmux versions
16
+ when relevant. Remove credentials and unrelated private data from examples.
17
+
18
+ I review reports and coordinate a fix and public disclosure with the reporter.
19
+ Please keep details private while we work out disclosure. I cannot guarantee
20
+ response or fix deadlines.
21
+
22
+ For ordinary bugs, use the [issue tracker](https://github.com/cosgroveb/rspec-osc7501/issues).
data/doc/behavior.rdoc CHANGED
@@ -7,14 +7,16 @@ ordinary formatter too if you want RSpec's progress or documentation output.
7
7
  == Output and settings
8
8
 
9
9
  The formatter uses the stream RSpec supplies, including <tt>--out</tt>. It leaves
10
- that stream open. Settings apply when RSpec constructs the formatter.
10
+ that stream open and flushes each frame when the stream supports flushing.
11
+ Settings apply when RSpec constructs the formatter.
11
12
 
12
13
  [<tt>RSPEC_OSC7501=auto</tt>]
13
- Emit to a TTY. This is the default, including an unset variable.
14
+ Emit to a TTY unless <tt>TERM=dumb</tt>. Streams without <tt>tty?</tt> remain silent.
15
+ This is the default, including an unset variable.
14
16
  [<tt>RSPEC_OSC7501=off</tt>]
15
17
  Emit no frames.
16
18
  [<tt>RSPEC_OSC7501=force</tt>]
17
- Emit to the selected stream even if it is not a TTY.
19
+ Emit to the selected stream even if it is not a TTY or <tt>TERM=dumb</tt>.
18
20
  [<tt>RSPEC_OSC7501_TITLE</tt>]
19
21
  Set a stable suite title. Default: <tt>RSpec</tt>.
20
22
 
@@ -30,8 +32,8 @@ description and completed, failed, and pending counts. Progress divides complete
30
32
  results by the initial example count and stays within 0 to 100. Pending examples
31
33
  count as completed. Zero-example runs omit progress.
32
34
 
33
- Intermediate updates occur at most once per 100 ms. Initial and final updates
34
- bypass throttling. A dry run identifies itself in its messages.
35
+ The formatter sends intermediate updates at most once per 100 ms and initial
36
+ and final updates without throttling. A dry run identifies itself in its messages.
35
37
 
36
38
  The final frame includes RSpec's summary counts and duration, with no progress:
37
39
 
@@ -42,15 +44,19 @@ The final frame includes RSpec's summary counts and duration, with no progress:
42
44
  exception ended the run. An empty suite with <tt>fail_if_no_examples</tt> also
43
45
  reports error.
44
46
  [<tt>idle</tt>]
45
- Interrupt, a successful early SystemExit, or an otherwise unexplained early-stop
46
- request ended the run.
47
+ An active Interrupt reports idle even with recorded failures. A zero-status
48
+ SystemExit reports idle only without failures or outside-example errors.
49
+ An otherwise unexplained early-stop request also reports idle.
47
50
 
48
51
  The formatter reads RSpec's private early-stop flag at summary time. A reached
49
52
  fail-fast threshold or outside-example error takes precedence over that flag.
53
+ Zero and negative fail-fast thresholds follow RSpec's threshold comparison.
50
54
  A coincident SIGINT can therefore report error. An early stop after a failure
51
55
  can report idle and retain the failure count. The formatter preserves RSpec's
52
56
  exit status.
53
57
 
58
+ An exception already active when the suite starts does not determine its result.
59
+
54
60
  Close emits no additional frame after a summary. A started run that closes
55
61
  without a summary reports an incomplete error once.
56
62
 
@@ -74,6 +80,11 @@ replaces invalid encoding, and truncates on character boundaries. Decoded titles
74
80
  are at most 192 bytes, decoded messages at most 2048 bytes, and frames at most
75
81
  4096 bytes.
76
82
 
83
+ Before sanitization, the formatter keeps at most 288 input bytes for titles and
84
+ 3072 for messages. This bounds sanitization work with 50% headroom for stripped
85
+ controls. Control-heavy input can produce shorter output. A character split by
86
+ the input cap becomes a replacement character before the final output limit.
87
+
77
88
  IOError or SystemCallError disables further status output for that formatter
78
89
  instance. Other exceptions propagate.
79
90
 
data/doc/usage.rdoc CHANGED
@@ -1,7 +1,7 @@
1
1
  = Usage
2
2
 
3
3
  Add OSC 7501 status alongside an ordinary RSpec formatter.
4
- See the {README}[rdoc-ref:README.md] for source installation.
4
+ See the {README}[rdoc-ref:README.md] for installation.
5
5
 
6
6
  == Configure a project
7
7
 
@@ -12,8 +12,8 @@ Add these options to your project's <tt>.rspec</tt>:
12
12
  --format RSpec::OSC7501::Formatter
13
13
 
14
14
  Run <tt>bundle exec rspec</tt>. RSpec prints ordinary progress and sends status
15
- frames to the formatter's TTY output. A terminal with OSC 7501 support can show
16
- the suite status.
15
+ frames to the formatter's TTY output unless <tt>TERM=dumb</tt>. A terminal with
16
+ OSC 7501 support can show the suite status.
17
17
 
18
18
  == Keep JSON separate
19
19
 
@@ -50,5 +50,5 @@ is <tt>RSpec</tt>.
50
50
 
51
51
  == Disable status
52
52
 
53
- Set <tt>RSPEC_OSC7501=off</tt> to disable frames while retaining the formatter
53
+ Set <tt>RSPEC_OSC7501=off</tt> to disable frames without changing the formatter
54
54
  configuration. See {Behavior}[rdoc-ref:doc/behavior.rdoc] for settings and limits.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'English'
4
+
3
5
  module RSpec
4
6
  # Reports RSpec suite status through OSC 7501 terminal records.
5
7
  module OSC7501
@@ -7,14 +9,14 @@ module RSpec
7
9
  # Select alongside an ordinary formatter to retain RSpec's text output.
8
10
  class Formatter
9
11
  RSpec::Core::Formatters.register self, :start, :example_started, :example_passed,
10
- :example_failed, :example_pending, :dump_summary, :close
12
+ :example_failed, :example_pending, :dump_summary, :close
11
13
 
12
14
  # Writes status to RSpec's +output+ stream without closing it.
13
15
  # Reads RSPEC_OSC7501 and RSPEC_OSC7501_TITLE at construction.
14
16
  # The optional +clock+ callable returns monotonic seconds for throttling.
15
17
  def initialize(output, clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) })
16
- @writer = Writer.new(output, mode: ENV.fetch("RSPEC_OSC7501", "auto"),
17
- title: ENV.fetch("RSPEC_OSC7501_TITLE", "RSpec"))
18
+ @writer = Writer.new(output, mode: ENV.fetch('RSPEC_OSC7501', 'auto'),
19
+ title: ENV.fetch('RSPEC_OSC7501_TITLE', 'RSpec'))
18
20
  @clock = clock
19
21
  @started = false
20
22
  @summarized = false
@@ -22,14 +24,15 @@ module RSpec
22
24
 
23
25
  # Starts suite progress from the example count in +notification+.
24
26
  def start(notification)
27
+ @inherited_exception = $ERROR_INFO
25
28
  @started = true
26
29
  @total = notification.count
27
30
  @completed = @failed = @pending = 0
28
31
  @current = nil
29
32
  @last_update = @clock.call
30
33
  message = "Running #{@total} examples"
31
- message += " (dry run)" if RSpec.configuration.dry_run
32
- @writer.emit(state: "working", msg: message, progress: progress)
34
+ message += ' (dry run)' if RSpec.configuration.dry_run
35
+ @writer.emit(state: 'working', msg: message, progress: progress)
33
36
  end
34
37
 
35
38
  # Sets the current example description and attempts a throttled update.
@@ -61,12 +64,13 @@ module RSpec
61
64
  # Emits the final state, counts, and duration from RSpec's summary.
62
65
  # Final output bypasses throttling and omits progress.
63
66
  def dump_summary(notification)
64
- active_exception = $!
67
+ active_exception = $ERROR_INFO
68
+ active_exception = nil if active_exception.equal?(@inherited_exception)
65
69
  @summarized = true
66
70
  state = final_state(notification, active_exception)
67
- outcome = { "done" => "Completed", "error" => "Failed", "idle" => "Stopped" }.fetch(state)
71
+ outcome = { 'done' => 'Completed', 'error' => 'Failed', 'idle' => 'Stopped' }.fetch(state)
68
72
  message = "#{outcome}: #{notification.totals_line} in #{notification.formatted_duration}"
69
- message += " (dry run)" if RSpec.configuration.dry_run
73
+ message += ' (dry run)' if RSpec.configuration.dry_run
70
74
  @writer.emit(state: state, msg: message)
71
75
  end
72
76
 
@@ -75,7 +79,7 @@ module RSpec
75
79
  return if @summarized || !@started || @closed
76
80
 
77
81
  @closed = true
78
- @writer.emit(state: "error", msg: "Incomplete: #{@completed}/#{@total} examples")
82
+ @writer.emit(state: 'error', msg: "Incomplete: #{@completed}/#{@total} examples")
79
83
  end
80
84
 
81
85
  private
@@ -88,7 +92,7 @@ module RSpec
88
92
  message += ", #{@failed} failures" if @failed.positive?
89
93
  message += ", #{@pending} pending" if @pending.positive?
90
94
  message += ": #{@current}" if @current
91
- @writer.emit(state: "working", msg: message, progress: progress)
95
+ @writer.emit(state: 'working', msg: message, progress: progress)
92
96
  @last_update = now
93
97
  end
94
98
 
@@ -99,21 +103,25 @@ module RSpec
99
103
  end
100
104
 
101
105
  def final_state(summary, active_exception)
102
- return "idle" if active_exception.is_a?(Interrupt)
103
- if active_exception.is_a?(SystemExit)
104
- return "error" if active_exception.status != 0 || summary.failure_count.positive? || summary.errors_outside_of_examples_count.positive?
106
+ return 'idle' if active_exception.is_a?(Interrupt)
107
+ return exit_state(summary, active_exception) if active_exception.is_a?(SystemExit)
108
+ return 'error' if active_exception || summary.errors_outside_of_examples_count.positive?
109
+ return stopped_state(summary) if early_stop?
105
110
 
106
- return "idle"
107
- end
108
- return "error" if active_exception || summary.errors_outside_of_examples_count.positive?
109
- if early_stop?
110
- return "error" if fail_fast_reached?(summary.failure_count)
111
+ unsuccessful_summary?(summary) ? 'error' : 'done'
112
+ end
111
113
 
112
- return "idle"
113
- end
114
- return "error" if summary.failure_count.positive? || (summary.example_count.zero? && RSpec.configuration.fail_if_no_examples)
114
+ def exit_state(summary, exception)
115
+ failed = summary.failure_count.positive? || summary.errors_outside_of_examples_count.positive?
116
+ exception.status.zero? && !failed ? 'idle' : 'error'
117
+ end
118
+
119
+ def stopped_state(summary)
120
+ fail_fast_reached?(summary.failure_count) ? 'error' : 'idle'
121
+ end
115
122
 
116
- "done"
123
+ def unsuccessful_summary?(summary)
124
+ summary.failure_count.positive? || (summary.example_count.zero? && RSpec.configuration.fail_if_no_examples)
117
125
  end
118
126
 
119
127
  # RSpec has no public early-stop event in 3.12 or 3.13.
@@ -124,7 +132,7 @@ module RSpec
124
132
  def fail_fast_reached?(failure_count)
125
133
  threshold = RSpec.configuration.fail_fast
126
134
  threshold = 1 if threshold == true
127
- threshold.is_a?(Integer) && threshold.positive? && failure_count >= threshold
135
+ threshold.is_a?(Integer) && failure_count >= threshold
128
136
  end
129
137
  end
130
138
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module OSC7501
5
- VERSION = "0.1.0"
5
+ VERSION = '0.1.2'
6
6
  end
7
7
  end
@@ -4,10 +4,10 @@ module RSpec
4
4
  module OSC7501
5
5
  class Writer # :nodoc: all
6
6
  def initialize(output, mode:, title:)
7
- raise ArgumentError, "RSPEC_OSC7501 must be auto, off, or force" unless %w[auto off force].include?(mode)
7
+ raise ArgumentError, 'RSPEC_OSC7501 must be auto, off, or force' unless %w[auto off force].include?(mode)
8
8
 
9
9
  @output = output
10
- @enabled = mode == "force" || (mode == "auto" && output.tty?)
10
+ @enabled = mode == 'force' || (mode == 'auto' && automatic_output?)
11
11
  @title = encode(title, 192) if @enabled
12
12
  rescue IOError, SystemCallError
13
13
  @enabled = false
@@ -16,23 +16,34 @@ module RSpec
16
16
  def emit(state:, msg:, progress: nil)
17
17
  return unless @enabled
18
18
 
19
- fields = ["app=rspec", "title=#{@title}", "state=#{state}", "msg=#{encode(msg, 2048)}"]
20
- fields << "progress=#{progress.to_i.clamp(0, 100)}" if state == "working" && !progress.nil?
19
+ fields = ['app=rspec', "title=#{@title}", "state=#{state}", "msg=#{encode(msg, 2048)}"]
20
+ fields << "progress=#{progress.to_i.clamp(0, 100)}" if state == 'working' && !progress.nil?
21
21
  @output.write("\e]7501;#{fields.join(':')}\e\\")
22
+ @output.flush if @output.respond_to?(:flush)
22
23
  rescue IOError, SystemCallError
23
24
  @enabled = false
24
25
  end
25
26
 
26
27
  private
27
28
 
29
+ def automatic_output?
30
+ ENV['TERM'] != 'dumb' && @output.respond_to?(:tty?) && @output.tty?
31
+ end
32
+
28
33
  def encode(text, byte_limit)
29
- clean = text.to_s.encode("UTF-8", invalid: :replace, undef: :replace).gsub(/[\u0000-\u001F\u007F-\u009F]/, "")
34
+ input = text.to_s.byteslice(0, sanitization_byte_limit(byte_limit))
35
+ clean = input.encode('UTF-8', invalid: :replace, undef: :replace).gsub(/[\u0000-\u001F\u007F-\u009F]/, '')
30
36
  bytes = 0
31
37
  bounded = clean.each_char.take_while do |char|
32
38
  bytes += char.bytesize
33
39
  bytes <= byte_limit
34
40
  end.join
35
- [bounded].pack("m0")
41
+ [bounded].pack('m0')
42
+ end
43
+
44
+ # Bound sanitization work with 50% headroom for stripped controls.
45
+ def sanitization_byte_limit(output_byte_limit)
46
+ output_byte_limit + output_byte_limit / 2
36
47
  end
37
48
  end
38
49
  end
data/lib/rspec/osc7501.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rspec/core"
4
- require_relative "osc7501/version"
5
- require_relative "osc7501/writer"
6
- require_relative "osc7501/formatter"
3
+ require 'rspec/core'
4
+ require_relative 'osc7501/version'
5
+ require_relative 'osc7501/writer'
6
+ require_relative 'osc7501/formatter'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-osc7501
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cosgrove
@@ -36,10 +36,13 @@ executables: []
36
36
  extensions: []
37
37
  extra_rdoc_files: []
38
38
  files:
39
+ - ACCESSIBILITY.md
39
40
  - CHANGELOG.md
41
+ - CODE_OF_CONDUCT.md
40
42
  - CONTRIBUTING.md
41
43
  - LICENSE
42
44
  - README.md
45
+ - SECURITY.md
43
46
  - doc/behavior.rdoc
44
47
  - doc/usage.rdoc
45
48
  - lib/rspec/osc7501.rb