ruby-anything 0.2.1 → 0.2.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.
- package/.claude-plugin/marketplace.json +12 -12
- package/.claude-plugin/plugin.json +3 -2
- package/README.md +17 -0
- package/docs/test-results.md +92 -0
- package/package.json +5 -3
- package/src/adapters.js +4 -1
- package/adapters/ruby/harness.rb +0 -134
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ruby-anything",
|
|
3
|
-
"owner": { "name": "
|
|
4
|
-
"description": "ruby-anything: migrate any app to Ruby on Rails one piece at a time, and prove it still behaves the same.",
|
|
5
|
-
"plugins": [
|
|
6
|
-
{
|
|
7
|
-
"name": "ruby-anything",
|
|
8
|
-
"source": "./",
|
|
9
|
-
"description": "Migrate any app to Rails + Hotwire + Tailwind + daisyUI, checked against the original's recorded behavior. Needs the ruby-anything CLI on PATH (npm i -g ruby-anything)."
|
|
10
|
-
}
|
|
11
|
-
]
|
|
12
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "ruby-anything",
|
|
3
|
+
"owner": { "name": "PortPilot" },
|
|
4
|
+
"description": "ruby-anything: migrate any app to Ruby on Rails one piece at a time, and prove it still behaves the same.",
|
|
5
|
+
"plugins": [
|
|
6
|
+
{
|
|
7
|
+
"name": "ruby-anything",
|
|
8
|
+
"source": "./",
|
|
9
|
+
"description": "Migrate any app to Rails + Hotwire + Tailwind + daisyUI, checked against the original's recorded behavior. Needs the ruby-anything CLI on PATH (npm i -g ruby-anything)."
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ruby-anything",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Migrate any app to Ruby on Rails 8 with Hotwire, Tailwind and daisyUI, one piece at a time, checked against the original's recorded behavior at every step. Needs the ruby-anything CLI on PATH (npm i -g ruby-anything).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -10,5 +10,6 @@
|
|
|
10
10
|
"daisyui",
|
|
11
11
|
"migration",
|
|
12
12
|
"mcp"
|
|
13
|
-
]
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://ruby-anything.vercel.app"
|
|
14
15
|
}
|
package/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
<p align="center">
|
|
4
4
|
<a href="https://www.npmjs.com/package/ruby-anything"><img src="https://img.shields.io/npm/v/ruby-anything?style=flat&colorA=111111&colorB=a51c1c&label=npm" alt="npm version"></a>
|
|
5
5
|
<a href="https://www.npmjs.com/package/ruby-anything"><img src="https://img.shields.io/npm/d18m/ruby-anything?style=flat&colorA=111111&colorB=a51c1c&label=npm%20downloads" alt="npm downloads"></a>
|
|
6
|
+
<a href="https://github.com/akkisavi/ruby-anything/actions/workflows/ruby-anything.yml"><img src="https://github.com/akkisavi/ruby-anything/actions/workflows/ruby-anything.yml/badge.svg?branch=master" alt="tests"></a>
|
|
6
7
|
<a href="#license"><img src="https://img.shields.io/badge/license-MIT-111111?style=flat&colorA=111111&colorB=a51c1c" alt="MIT license"></a>
|
|
7
8
|
</p>
|
|
8
9
|
|
|
@@ -10,6 +11,10 @@
|
|
|
10
11
|
Migrate your app to Ruby on Rails, and prove it still behaves the same.
|
|
11
12
|
</p>
|
|
12
13
|
|
|
14
|
+
<p align="center">
|
|
15
|
+
<b>Website and docs:</b> <a href="https://ruby-anything.vercel.app">ruby-anything.vercel.app</a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
13
18
|
<p align="center">
|
|
14
19
|
Rails 8 · Hotwire (Turbo + Stimulus) · Tailwind CSS · daisyUI<br>
|
|
15
20
|
from TypeScript, JavaScript, Python, Go, Java/Spring Boot, Kotlin, C#, PHP, Rust and Swift
|
|
@@ -90,6 +95,18 @@ Everything it writes lives in `<repo>/rails/`: the Rails app, and `rails/port/`
|
|
|
90
95
|
| `ruby-anything app lift <repo>` | Remove the proxy once nothing falls back |
|
|
91
96
|
| `ruby-anything setup \| doctor \| mcp` | Install for agents, check runtimes, MCP server |
|
|
92
97
|
|
|
98
|
+
## Tested
|
|
99
|
+
|
|
100
|
+
Every push runs the end-to-end suite on **Ubuntu, Windows and macOS** in
|
|
101
|
+
[GitHub Actions](https://github.com/akkisavi/ruby-anything/actions/workflows/ruby-anything.yml).
|
|
102
|
+
It drives real Python and Node originals through the recorders, real Ruby ports through the
|
|
103
|
+
replay harness, and real HTTP, SMTP and SQLite for side effects. It checks both that a correct
|
|
104
|
+
port passes and that a wrong one is caught: half-up vs banker's rounding, `1` vs `1.0`, a
|
|
105
|
+
forgotten email, a wrong exit code, an edited recording, a recorded answer pasted into the port.
|
|
106
|
+
|
|
107
|
+
**22 of 22 pass.** Every test, with its result and time: [test results](docs/test-results.md)
|
|
108
|
+
(regenerate with `npm run test:report`).
|
|
109
|
+
|
|
93
110
|
## In CI
|
|
94
111
|
|
|
95
112
|
```yaml
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Test results
|
|
2
|
+
|
|
3
|
+
<!-- generated by `npm run test:report`; do not edit by hand -->
|
|
4
|
+
|
|
5
|
+
**22 passed, 0 failed** in 23.2s, ruby-anything 0.2.1 at commit `c5873f2`, 2026-11-28.
|
|
6
|
+
|
|
7
|
+
These are end-to-end tests: they run real Python and Node originals through the recorders,
|
|
8
|
+
real Ruby ports through the replay harness, and real HTTP servers, SMTP and SQLite for side
|
|
9
|
+
effects. The workflow tests check both that a correct port passes and that a wrong one is caught.
|
|
10
|
+
|
|
11
|
+
Every push also runs this suite on Ubuntu, Windows and macOS in GitHub Actions:
|
|
12
|
+
[latest runs](https://github.com/akkisavi/ruby-anything/actions/workflows/ruby-anything.yml).
|
|
13
|
+
|
|
14
|
+
| Environment | Version |
|
|
15
|
+
|---|---|
|
|
16
|
+
| OS | win32 x64 |
|
|
17
|
+
| Node | v24.6.0 |
|
|
18
|
+
| Python | Python 3.12.10 |
|
|
19
|
+
| Ruby | ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x64-mingw-ucrt] |
|
|
20
|
+
|
|
21
|
+
## Whole app over HTTP, with side effects
|
|
22
|
+
|
|
23
|
+
`test/app.test.js`
|
|
24
|
+
|
|
25
|
+
| Result | Test | Time |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| ✅ pass | app record and replay against the original | 1404 ms |
|
|
28
|
+
| ✅ pass | side effects: payment call, email and database rows are recorded and checked | 7009 ms |
|
|
29
|
+
|
|
30
|
+
## Whole CLI app: record, front door, wire, lift
|
|
31
|
+
|
|
32
|
+
`test/cli.test.js`
|
|
33
|
+
|
|
34
|
+
| Result | Test | Time |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| ✅ pass | CLI record: exit codes, output, stdin and files, without touching the checkout | 1387 ms |
|
|
37
|
+
| ✅ pass | CLI front door: fallback, wire, catch a wrong exit code, lift | 5082 ms |
|
|
38
|
+
|
|
39
|
+
## Comparison rules (numbers, errors, HTML, noise, side effects)
|
|
40
|
+
|
|
41
|
+
`test/compare.test.js`
|
|
42
|
+
|
|
43
|
+
| Result | Test | Time |
|
|
44
|
+
|---|---|---|
|
|
45
|
+
| ✅ pass | int and float stay apart | 1 ms |
|
|
46
|
+
| ✅ pass | exact doubles from different harnesses compare equal | 0 ms |
|
|
47
|
+
| ✅ pass | error families map across languages | 0 ms |
|
|
48
|
+
| ✅ pass | compareCase names the first difference | 0 ms |
|
|
49
|
+
| ✅ pass | html text and replay modes | 2 ms |
|
|
50
|
+
| ✅ pass | noise becomes wildcards, word by word | 0 ms |
|
|
51
|
+
| ✅ pass | side effects are compared | 0 ms |
|
|
52
|
+
|
|
53
|
+
## --pin-clock and drift
|
|
54
|
+
|
|
55
|
+
`test/drift.test.js`
|
|
56
|
+
|
|
57
|
+
| Result | Test | Time |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| ✅ pass | --pin-clock: the original and the port see the same instant | 1223 ms |
|
|
60
|
+
| ✅ pass | drift: nothing changed, then an upstream change is reported | 1405 ms |
|
|
61
|
+
|
|
62
|
+
## record --from-tests (Python unittest, node --test)
|
|
63
|
+
|
|
64
|
+
`test/fromtests.test.js`
|
|
65
|
+
|
|
66
|
+
| Result | Test | Time |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| ✅ pass | Python unittest calls are recorded | 497 ms |
|
|
69
|
+
| ✅ pass | node --test calls are recorded | 405 ms |
|
|
70
|
+
| ✅ pass | a leftover backup from a crash is restored first | 414 ms |
|
|
71
|
+
|
|
72
|
+
## One function: analyze, bridge, record, diff, gate, rules
|
|
73
|
+
|
|
74
|
+
`test/units.test.js`
|
|
75
|
+
|
|
76
|
+
| Result | Test | Time |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| ✅ pass | analyze finds the functions | 185 ms |
|
|
79
|
+
| ✅ pass | bridge writes a stub that gate rejects | 653 ms |
|
|
80
|
+
| ✅ pass | a correct port passes diff and gate | 1496 ms |
|
|
81
|
+
| ✅ pass | diff catches half-up rounding and int vs float | 634 ms |
|
|
82
|
+
| ✅ pass | gate rejects copied answers and edited recordings | 691 ms |
|
|
83
|
+
| ✅ pass | rules are kept | 89 ms |
|
|
84
|
+
|
|
85
|
+
## Run it yourself
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
cd packages/ruby-anything
|
|
89
|
+
npm install
|
|
90
|
+
npm test # the suite
|
|
91
|
+
npm run test:report # the suite, and rewrite this file
|
|
92
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ruby-anything",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Migrate any app (TypeScript, JavaScript, Python, Go, Java/Spring, Kotlin, C#, PHP, Rust, Swift) to Ruby on Rails with Hotwire, Tailwind and daisyUI, one piece at a time, checked against the original's recorded behavior at every step.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ruby",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"url": "git+https://github.com/akkisavi/ruby-anything.git",
|
|
22
22
|
"directory": "packages/ruby-anything"
|
|
23
23
|
},
|
|
24
|
-
"homepage": "https://
|
|
24
|
+
"homepage": "https://ruby-anything.vercel.app",
|
|
25
25
|
"bugs": {
|
|
26
26
|
"url": "https://github.com/akkisavi/ruby-anything/issues"
|
|
27
27
|
},
|
|
@@ -43,7 +43,9 @@
|
|
|
43
43
|
"!adapters/node/node_modules"
|
|
44
44
|
],
|
|
45
45
|
"scripts": {
|
|
46
|
-
"
|
|
46
|
+
"prepack": "node scripts/sync-adapters.js",
|
|
47
|
+
"test": "node scripts/test.js",
|
|
48
|
+
"test:report": "node scripts/test-report.js"
|
|
47
49
|
},
|
|
48
50
|
"engines": {
|
|
49
51
|
"node": ">=18"
|
package/src/adapters.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
// Runs
|
|
2
|
+
// Runs PortPilot's language adapters (the recorders) on the original code.
|
|
3
3
|
// Recording EXECUTES the original: work on a copy, with a test database.
|
|
4
4
|
const fs = require('node:fs')
|
|
5
5
|
const path = require('node:path')
|
|
@@ -8,6 +8,9 @@ const { PKG, python, which, runHarness, canon } = require('./util')
|
|
|
8
8
|
const POLYGLOT = { go: 'go', java: 'javac', kotlin: 'kotlinc', csharp: 'dotnet', php: 'php', rust: 'rustc', swift: 'swiftc', ruby: 'ruby' }
|
|
9
9
|
|
|
10
10
|
function adaptersDir() {
|
|
11
|
+
// Inside the PortPilot repo the live adapters win over a copy left by `npm pack`.
|
|
12
|
+
const dev = path.resolve(PKG, '..', '..', 'adapters')
|
|
13
|
+
if (fs.existsSync(path.join(dev, 'polyglot', 'harness.py'))) return dev
|
|
11
14
|
const bundled = path.join(PKG, 'adapters')
|
|
12
15
|
if (fs.existsSync(path.join(bundled, 'polyglot'))) return bundled
|
|
13
16
|
throw new Error('language adapters missing: reinstall ruby-anything')
|
package/adapters/ruby/harness.rb
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
# PortPilot Ruby adapter.
|
|
2
|
-
#
|
|
3
|
-
# Runs in a separate process (never inside Rails). Reads one JSON request on stdin and
|
|
4
|
-
# writes JSON lines on stdout. The migrated code must define `module Migrated` with
|
|
5
|
-
# singleton methods named like the original functions.
|
|
6
|
-
#
|
|
7
|
-
# Commands: replay (run each case once, capture behaviour), bench (time N iterations per case).
|
|
8
|
-
require "json"
|
|
9
|
-
require "stringio"
|
|
10
|
-
require "tmpdir"
|
|
11
|
-
require "digest"
|
|
12
|
-
require "set"
|
|
13
|
-
|
|
14
|
-
REAL_STDOUT = $stdout.dup
|
|
15
|
-
REAL_STDOUT.sync = true
|
|
16
|
-
|
|
17
|
-
def emit(event, **data)
|
|
18
|
-
REAL_STDOUT.write(JSON.generate(data.merge(event: event)) + "\n")
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def encode(value)
|
|
22
|
-
case value
|
|
23
|
-
when nil, true, false, String, Integer then value
|
|
24
|
-
when Float
|
|
25
|
-
return { "$float" => "nan" } if value.nan?
|
|
26
|
-
return { "$float" => value.positive? ? "inf" : "-inf" } if value.infinite?
|
|
27
|
-
return { "$float" => "-0.0" } if value.zero? && (1.0 / value).negative?
|
|
28
|
-
return { "$float" => value.to_s } if value == value.floor && value.abs > 2**53 # inexact integral double
|
|
29
|
-
|
|
30
|
-
value
|
|
31
|
-
when Array then value.map { |v| encode(v) }
|
|
32
|
-
when Hash then value.to_h { |k, v| [ k.to_s, encode(v) ] }
|
|
33
|
-
when Set then { "$set" => value.map { |v| encode(v) }.sort_by { |v| JSON.generate(v) } }
|
|
34
|
-
else { "$repr" => value.inspect[0, 200] }
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def decode(value)
|
|
39
|
-
case value
|
|
40
|
-
when Array then value.map { |v| decode(v) }
|
|
41
|
-
when Hash
|
|
42
|
-
if value.key?("$float")
|
|
43
|
-
{ "nan" => Float::NAN, "inf" => Float::INFINITY, "-inf" => -Float::INFINITY, "-0.0" => -0.0 }.fetch(value["$float"]) { Float(value["$float"]) }
|
|
44
|
-
elsif value.key?("$bytes") then value["$bytes"].unpack1("m0").b
|
|
45
|
-
elsif value.key?("$set") then Set.new(decode(value["$set"]))
|
|
46
|
-
else value.transform_values { |v| decode(v) }
|
|
47
|
-
end
|
|
48
|
-
else value
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def snapshot(root)
|
|
53
|
-
Dir.glob("**/*", File::FNM_DOTMATCH, base: root).filter_map do |rel|
|
|
54
|
-
full = File.join(root, rel)
|
|
55
|
-
next unless File.file?(full)
|
|
56
|
-
data = File.binread(full)
|
|
57
|
-
{ "path" => rel, "size" => data.bytesize, "sha256" => Digest::SHA256.hexdigest(data) }
|
|
58
|
-
end.sort_by { |e| e["path"] }
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def call(function, case_data)
|
|
62
|
-
args = decode(case_data.fetch("args", []))
|
|
63
|
-
kwargs = decode(case_data.fetch("kwargs", {})).transform_keys(&:to_sym)
|
|
64
|
-
kwargs.empty? ? Migrated.public_send(function, *args) : Migrated.public_send(function, *args, **kwargs)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def run_case(function, case_data)
|
|
68
|
-
out = StringIO.new
|
|
69
|
-
err = StringIO.new
|
|
70
|
-
Dir.mktmpdir("pp-case-") do |scratch|
|
|
71
|
-
Dir.chdir(scratch) do
|
|
72
|
-
started = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
|
|
73
|
-
$stdout, $stderr = out, err
|
|
74
|
-
outcome =
|
|
75
|
-
begin
|
|
76
|
-
{ "kind" => "return", "value" => encode(call(function, case_data)) }
|
|
77
|
-
rescue StandardError => e
|
|
78
|
-
{ "kind" => "raise", "type" => e.class.name, "message" => e.message }
|
|
79
|
-
ensure
|
|
80
|
-
$stdout, $stderr = STDOUT, STDERR
|
|
81
|
-
end
|
|
82
|
-
duration = (Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond) - started) / 1000
|
|
83
|
-
{ "outcome" => outcome, "stdout" => out.string, "stderr" => err.string,
|
|
84
|
-
"effects" => snapshot(scratch), "duration_us" => duration }
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def load_code(path)
|
|
90
|
-
# Silence output produced while loading the file itself.
|
|
91
|
-
$stdout = StringIO.new
|
|
92
|
-
load(path)
|
|
93
|
-
ensure
|
|
94
|
-
$stdout = STDOUT
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
request = JSON.parse($stdin.read)
|
|
98
|
-
load_code(request.fetch("code_file"))
|
|
99
|
-
function = request.fetch("function")
|
|
100
|
-
unless defined?(Migrated) && Migrated.respond_to?(function)
|
|
101
|
-
emit("fatal", message: "Migrated.#{function} is not defined. Define `module Migrated; def self.#{function}(...)`.")
|
|
102
|
-
exit 2
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
emit("plan", total: request["cases"].size, runtime: "ruby #{RUBY_VERSION}")
|
|
106
|
-
case request.fetch("command")
|
|
107
|
-
when "replay"
|
|
108
|
-
request["cases"].each { |c| emit("case", ref: c["ref"], **run_case(function, c).transform_keys(&:to_sym)) }
|
|
109
|
-
when "bench"
|
|
110
|
-
iterations = request.fetch("iterations", 30).to_i.clamp(1, 10_000)
|
|
111
|
-
request["cases"].each do |c|
|
|
112
|
-
samples = Dir.mktmpdir("pp-bench-") do |scratch|
|
|
113
|
-
Dir.chdir(scratch) do
|
|
114
|
-
$stdout = StringIO.new
|
|
115
|
-
Array.new(iterations) do
|
|
116
|
-
started = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
|
|
117
|
-
begin
|
|
118
|
-
call(function, c)
|
|
119
|
-
rescue StandardError
|
|
120
|
-
nil
|
|
121
|
-
end
|
|
122
|
-
Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond) - started
|
|
123
|
-
end
|
|
124
|
-
ensure
|
|
125
|
-
$stdout = STDOUT
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
emit("case", ref: c["ref"], samples_ns: samples, peak_memory_bytes: nil)
|
|
129
|
-
end
|
|
130
|
-
else
|
|
131
|
-
emit("fatal", message: "unknown command")
|
|
132
|
-
exit 2
|
|
133
|
-
end
|
|
134
|
-
emit("done")
|