Kérésre: minden magyarázó komment kikerült a forrásfájlokból — 89 Ruby, 16 TypeScript, 14 Vue, plusz a CSS/JS/CJS. Nem soralapú kereséssel: a Ruby-t a Ripper tokenizálta, a JS/TS/CSS-t állapotgép járta végig, hogy az URL-ekben, reguláris kifejezésekben és heredocokban álló // és # jelek helyükön maradjanak. Három komment maradt, mert nélkülük nem indul a kód: az entrypoint.sh shebangja, a vite-env.d.ts hármas perjeles referenciája, és a sanitize teszt @vitest-environment direktívája (ez utóbbi a magyarázó része nélkül). Egy helyen kódot is kellett írni: a CommandBlock másolás-hibaágán a komment volt a catch egyetlen tartalma, és üres blokkot az eslint nem enged — a copied jelző visszaállítása került a helyére. A yaml, Dockerfile, Makefile, erb és markdown fájlokat nem érintettem. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
59 lines
1.7 KiB
Ruby
59 lines
1.7 KiB
Ruby
require "rails_helper"
|
|
require "tmpdir"
|
|
|
|
RSpec.describe WarpEngine::Storage do
|
|
let(:tmpdir) { Dir.mktmpdir }
|
|
|
|
before do
|
|
allow(WarpEngine.config).to receive(:file_container_path).and_return(tmpdir)
|
|
WarpEngine::Storage.reset!
|
|
end
|
|
|
|
after { FileUtils.rm_rf(tmpdir) }
|
|
|
|
describe ".adapter" do
|
|
it "defaults to the local filesystem" do
|
|
allow(WarpEngine.config).to receive(:storage_adapter).and_return(:local)
|
|
|
|
expect(described_class.adapter).to be_a(described_class::LocalAdapter)
|
|
expect(described_class).to be_local
|
|
end
|
|
|
|
it "returns whatever object the host configured" do
|
|
custom = Object.new
|
|
allow(WarpEngine.config).to receive(:storage_adapter).and_return(custom)
|
|
|
|
expect(described_class.adapter).to eq(custom)
|
|
expect(described_class).not_to be_local
|
|
end
|
|
end
|
|
|
|
describe described_class::LocalAdapter do
|
|
subject(:adapter) { described_class.new }
|
|
|
|
before { File.write(File.join(tmpdir, "game-1.0.zip"), "zip") }
|
|
|
|
it "sees files and directories under the container" do
|
|
FileUtils.mkdir_p(File.join(tmpdir, "game-1.0"))
|
|
|
|
expect(adapter.file?("game-1.0.zip")).to be(true)
|
|
expect(adapter.directory?("game-1.0")).to be(true)
|
|
expect(adapter.file?("missing.zip")).to be(false)
|
|
end
|
|
|
|
it "refuses paths escaping the container" do
|
|
outside = File.join(Dir.mktmpdir, "secret.txt")
|
|
File.write(outside, "nope")
|
|
|
|
expect(adapter.file?("../#{File.basename(File.dirname(outside))}/secret.txt")).to be(false)
|
|
end
|
|
|
|
it "locates a file as an absolute path" do
|
|
location = adapter.locate("game-1.0.zip")
|
|
|
|
expect(location).to be_file
|
|
expect(location.path).to eq(File.join(tmpdir, "game-1.0.zip"))
|
|
end
|
|
end
|
|
end
|