Upload 18 files
Browse files- app/main.py +224 -0
- golem/DESCRIPTION +24 -0
- golem/LICENSE +15 -0
- golem/NAMESPACE +2 -0
- golem/R/app_server.R +4 -0
- golem/R/app_ui.R +17 -0
- golem/R/mod_report.R +56 -0
- golem/R/mod_submit.R +73 -0
- golem/R/run_app.R +8 -0
- golem/R/service.R +25 -0
- golem/R/utils.R +3 -0
- golem/inst/app/www/rxv.css +10 -0
- golem/inst/app/www/rxv.js +3 -0
- runner/Dockerfile +15 -0
- runner/requirements.txt +4 -0
- runner/service.py +135 -0
- runner/validate.R +301 -0
- tests/test_api_contract.py +15 -0
app/main.py
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Project RxV public intake and report API.
|
| 2 |
+
|
| 3 |
+
The web process stores metadata only. It never checks out, installs, or executes
|
| 4 |
+
submitted R code; that work belongs to the separately isolated Runner service.
|
| 5 |
+
"""
|
| 6 |
+
from __future__ import annotations
|
| 7 |
+
|
| 8 |
+
import asyncio
|
| 9 |
+
import hashlib
|
| 10 |
+
import json
|
| 11 |
+
import os
|
| 12 |
+
import re
|
| 13 |
+
import secrets
|
| 14 |
+
import sqlite3
|
| 15 |
+
import time
|
| 16 |
+
import uuid
|
| 17 |
+
import zipfile
|
| 18 |
+
from contextlib import closing
|
| 19 |
+
from pathlib import Path
|
| 20 |
+
from typing import Literal
|
| 21 |
+
from urllib.parse import urlparse
|
| 22 |
+
|
| 23 |
+
import httpx
|
| 24 |
+
from fastapi import BackgroundTasks, FastAPI, File, Form, HTTPException, Request, UploadFile
|
| 25 |
+
from fastapi.responses import FileResponse, HTMLResponse
|
| 26 |
+
from fastapi.staticfiles import StaticFiles
|
| 27 |
+
from pydantic import BaseModel, HttpUrl
|
| 28 |
+
|
| 29 |
+
APP_ROOT = Path(__file__).parent
|
| 30 |
+
DATA_ROOT = Path(os.getenv("RXV_DATA_ROOT", "/data"))
|
| 31 |
+
UPLOAD_ROOT = Path(os.getenv("RXV_UPLOAD_ROOT", str(DATA_ROOT / "uploads")))
|
| 32 |
+
REPORT_ROOT = Path(os.getenv("RXV_REPORT_ROOT", str(DATA_ROOT / "reports")))
|
| 33 |
+
DB_PATH = DATA_ROOT / "rxv.sqlite3"
|
| 34 |
+
MAX_UPLOAD_BYTES = int(os.getenv("RXV_MAX_UPLOAD_BYTES", "262144000"))
|
| 35 |
+
RUNNER_URL = os.getenv("RXV_RUNNER_URL", "")
|
| 36 |
+
RUNNER_TOKEN = os.getenv("RXV_RUNNER_TOKEN", "")
|
| 37 |
+
CALLBACK_BASE_URL = os.getenv("RXV_CALLBACK_BASE_URL", "")
|
| 38 |
+
DEMO_MODE = os.getenv("RXV_DEMO_MODE", "false").lower() == "true"
|
| 39 |
+
GITHUB_RE = re.compile(r"^https://github\.com/[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+/?$")
|
| 40 |
+
|
| 41 |
+
app = FastAPI(title="Project RxV", version="0.1.0")
|
| 42 |
+
app.mount("/static", StaticFiles(directory=APP_ROOT / "static"), name="static")
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def db() -> sqlite3.Connection:
|
| 46 |
+
connection = sqlite3.connect(DB_PATH)
|
| 47 |
+
connection.row_factory = sqlite3.Row
|
| 48 |
+
return connection
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def initialize() -> None:
|
| 52 |
+
DATA_ROOT.mkdir(parents=True, exist_ok=True)
|
| 53 |
+
UPLOAD_ROOT.mkdir(parents=True, exist_ok=True)
|
| 54 |
+
REPORT_ROOT.mkdir(parents=True, exist_ok=True)
|
| 55 |
+
with closing(db()) as con:
|
| 56 |
+
con.execute("""CREATE TABLE IF NOT EXISTS runs (
|
| 57 |
+
id TEXT PRIMARY KEY, source_type TEXT NOT NULL, source_ref TEXT NOT NULL,
|
| 58 |
+
profile TEXT NOT NULL, status TEXT NOT NULL, created_at INTEGER NOT NULL,
|
| 59 |
+
updated_at INTEGER NOT NULL, report_json TEXT, error TEXT, sha256 TEXT
|
| 60 |
+
)""")
|
| 61 |
+
con.commit()
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@app.on_event("startup")
|
| 65 |
+
async def startup() -> None:
|
| 66 |
+
initialize()
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class CallbackPayload(BaseModel):
|
| 70 |
+
status: Literal["passed", "failed", "error"]
|
| 71 |
+
report: dict | None = None
|
| 72 |
+
error: str | None = None
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def fetch_run(run_id: str) -> dict:
|
| 76 |
+
with closing(db()) as con:
|
| 77 |
+
row = con.execute("SELECT * FROM runs WHERE id = ?", (run_id,)).fetchone()
|
| 78 |
+
if row is None:
|
| 79 |
+
raise HTTPException(404, "Validation run not found")
|
| 80 |
+
item = dict(row)
|
| 81 |
+
item["report"] = json.loads(item.pop("report_json")) if item.get("report_json") else None
|
| 82 |
+
return item
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def update_run(run_id: str, *, status: str, report: dict | None = None, error: str | None = None) -> None:
|
| 86 |
+
with closing(db()) as con:
|
| 87 |
+
con.execute(
|
| 88 |
+
"UPDATE runs SET status=?, updated_at=?, report_json=?, error=? WHERE id=?",
|
| 89 |
+
(status, int(time.time()), json.dumps(report) if report else None, error, run_id),
|
| 90 |
+
)
|
| 91 |
+
con.commit()
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def validate_github_url(value: str) -> str:
|
| 95 |
+
parsed = urlparse(value)
|
| 96 |
+
if parsed.username or parsed.password or parsed.hostname != "github.com" or parsed.query or parsed.fragment:
|
| 97 |
+
raise HTTPException(422, "Use a public github.com owner/repository URL without query parameters.")
|
| 98 |
+
normal = value.rstrip("/")
|
| 99 |
+
if not GITHUB_RE.fullmatch(normal):
|
| 100 |
+
raise HTTPException(422, "Use a public github.com owner/repository URL.")
|
| 101 |
+
return normal
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
async def save_upload(upload: UploadFile, run_id: str) -> tuple[str, str]:
|
| 105 |
+
if not upload.filename or not upload.filename.lower().endswith(".zip"):
|
| 106 |
+
raise HTTPException(422, "Upload an R package source ZIP file.")
|
| 107 |
+
target = UPLOAD_ROOT / f"{run_id}.zip"
|
| 108 |
+
digest = hashlib.sha256()
|
| 109 |
+
size = 0
|
| 110 |
+
with target.open("wb") as output:
|
| 111 |
+
while chunk := await upload.read(1024 * 1024):
|
| 112 |
+
size += len(chunk)
|
| 113 |
+
if size > MAX_UPLOAD_BYTES:
|
| 114 |
+
output.close()
|
| 115 |
+
target.unlink(missing_ok=True)
|
| 116 |
+
raise HTTPException(413, "ZIP exceeds the configured upload limit.")
|
| 117 |
+
digest.update(chunk)
|
| 118 |
+
output.write(chunk)
|
| 119 |
+
try:
|
| 120 |
+
with zipfile.ZipFile(target) as archive:
|
| 121 |
+
entries = archive.infolist()
|
| 122 |
+
expanded = sum(i.file_size for i in entries)
|
| 123 |
+
if len(entries) > 10_000 or expanded > 2_000_000_000 or (size and expanded / size > 200):
|
| 124 |
+
raise HTTPException(422, "ZIP archive exceeds safe expansion limits.")
|
| 125 |
+
for entry in entries:
|
| 126 |
+
path = Path(entry.filename)
|
| 127 |
+
if path.is_absolute() or ".." in path.parts:
|
| 128 |
+
raise HTTPException(422, "ZIP contains an unsafe path.")
|
| 129 |
+
except zipfile.BadZipFile as exc:
|
| 130 |
+
target.unlink(missing_ok=True)
|
| 131 |
+
raise HTTPException(422, "Invalid ZIP archive.") from exc
|
| 132 |
+
return str(target), digest.hexdigest()
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def demo_report(run_id: str) -> dict:
|
| 136 |
+
return {
|
| 137 |
+
"run_id": run_id, "score": 88, "verdict": "passed_with_warnings",
|
| 138 |
+
"environment": {"r_version": "4.4", "platform": "linux", "network": "disabled"},
|
| 139 |
+
"suites": [
|
| 140 |
+
{"name": "Package structure", "status": "passed", "summary": "Required package components and test layout detected."},
|
| 141 |
+
{"name": "Metadata, license & repository hygiene", "status": "passed", "summary": "Metadata, license, README, NEWS, and build-ignore policy passed."},
|
| 142 |
+
{"name": "AST & security", "status": "warning", "summary": "1 external-command call requires review."},
|
| 143 |
+
{"name": "Secrets, supply-chain & unsafe-content scan", "status": "passed", "summary": "No credential or shell-download patterns detected."},
|
| 144 |
+
{"name": "Maintainability & complexity", "status": "passed", "summary": "Complexity and source-size thresholds passed."},
|
| 145 |
+
{"name": "Dependency compatibility", "status": "passed", "summary": "Declared dependencies resolved in the validation image."},
|
| 146 |
+
{"name": "Package integrity", "status": "passed", "summary": "Build and clean install completed."},
|
| 147 |
+
{"name": "CRAN readiness", "status": "passed", "summary": "R CMD check --as-cran completed."},
|
| 148 |
+
{"name": "Test confidence", "status": "passed", "summary": "48 tests passed · 84% coverage."},
|
| 149 |
+
{"name": "Documentation", "status": "passed", "summary": "All exported objects documented."},
|
| 150 |
+
{"name": "Visual & UI regression", "status": "skipped", "summary": "No vdiffr or Shiny snapshots discovered."},
|
| 151 |
+
],
|
| 152 |
+
"findings": [{"severity": "medium", "rule": "RXV-AST-004", "file": "R/import.R", "line": 22, "message": "system2() call should be allow-listed or replaced."}],
|
| 153 |
+
"artifacts": [],
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
async def dispatch(run_id: str, source: dict, profile: str) -> None:
|
| 158 |
+
if DEMO_MODE:
|
| 159 |
+
await asyncio.sleep(1.2)
|
| 160 |
+
update_run(run_id, status="passed", report=demo_report(run_id))
|
| 161 |
+
return
|
| 162 |
+
if not RUNNER_URL or not RUNNER_TOKEN or not CALLBACK_BASE_URL:
|
| 163 |
+
update_run(run_id, status="error", error="Runner is not configured. The package was not executed.")
|
| 164 |
+
return
|
| 165 |
+
payload = {"run_id": run_id, "source": source, "profile": profile, "callback_url": f"{CALLBACK_BASE_URL.rstrip('/')}/api/runs/{run_id}/complete"}
|
| 166 |
+
try:
|
| 167 |
+
async with httpx.AsyncClient(timeout=15) as client:
|
| 168 |
+
response = await client.post(f"{RUNNER_URL.rstrip('/')}/jobs", json=payload, headers={"Authorization": f"Bearer {RUNNER_TOKEN}"})
|
| 169 |
+
response.raise_for_status()
|
| 170 |
+
except Exception as exc: # runner errors intentionally do not expose internals to public clients
|
| 171 |
+
update_run(run_id, status="error", error=f"Runner dispatch failed: {type(exc).__name__}")
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
@app.get("/", response_class=HTMLResponse)
|
| 175 |
+
async def index() -> HTMLResponse:
|
| 176 |
+
return HTMLResponse("<h1>Project RxV API</h1><p>This service is consumed by the Project RxV Golem interface.</p>")
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
@app.post("/api/submissions", status_code=202)
|
| 180 |
+
async def create_submission(
|
| 181 |
+
background_tasks: BackgroundTasks,
|
| 182 |
+
github_url: str | None = Form(default=None),
|
| 183 |
+
package_zip: UploadFile | None = File(default=None),
|
| 184 |
+
profile: Literal["rapid", "standard", "release"] = Form(default="standard"),
|
| 185 |
+
) -> dict:
|
| 186 |
+
if bool(github_url) == bool(package_zip):
|
| 187 |
+
raise HTTPException(422, "Provide exactly one source: a GitHub URL or a ZIP upload.")
|
| 188 |
+
run_id = uuid.uuid4().hex
|
| 189 |
+
source: dict
|
| 190 |
+
sha = None
|
| 191 |
+
if github_url:
|
| 192 |
+
source = {"type": "github", "url": validate_github_url(github_url)}
|
| 193 |
+
source_ref = source["url"]
|
| 194 |
+
else:
|
| 195 |
+
artifact_path, sha = await save_upload(package_zip, run_id) # type: ignore[arg-type]
|
| 196 |
+
source = {"type": "zip", "artifact_path": artifact_path, "filename": package_zip.filename}
|
| 197 |
+
source_ref = package_zip.filename or "package.zip"
|
| 198 |
+
now = int(time.time())
|
| 199 |
+
with closing(db()) as con:
|
| 200 |
+
con.execute("INSERT INTO runs VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (run_id, source["type"], source_ref, profile, "queued", now, now, None, None, sha))
|
| 201 |
+
con.commit()
|
| 202 |
+
background_tasks.add_task(dispatch, run_id, source, profile)
|
| 203 |
+
return {"id": run_id, "status": "queued", "poll_url": f"/api/runs/{run_id}"}
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
@app.get("/api/runs/{run_id}")
|
| 207 |
+
async def get_run(run_id: str) -> dict:
|
| 208 |
+
return fetch_run(run_id)
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
@app.post("/api/runs/{run_id}/complete")
|
| 212 |
+
async def complete_run(run_id: str, payload: CallbackPayload, request: Request) -> dict:
|
| 213 |
+
# Runner-to-UI shared token. In production replace with workload identity/mTLS.
|
| 214 |
+
expected = f"Bearer {RUNNER_TOKEN}"
|
| 215 |
+
if not RUNNER_TOKEN or not secrets.compare_digest(request.headers.get("Authorization", ""), expected):
|
| 216 |
+
raise HTTPException(401, "Invalid runner credential")
|
| 217 |
+
fetch_run(run_id)
|
| 218 |
+
update_run(run_id, status=payload.status, report=payload.report, error=payload.error)
|
| 219 |
+
return {"ok": True}
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
@app.get("/api/health")
|
| 223 |
+
async def health() -> dict:
|
| 224 |
+
return {"service": "project-rxv", "status": "ok", "demo_mode": DEMO_MODE}
|
golem/DESCRIPTION
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Package: rxv
|
| 2 |
+
Title: Project RxV Public Validation Console
|
| 3 |
+
Version: 0.1.0
|
| 4 |
+
Authors@R: person("Project", "RxV", email = "maintainers@example.invalid", role = c("aut", "cre"))
|
| 5 |
+
Description: A Golem/Shiny public interface for submitting R packages to the
|
| 6 |
+
Project RxV isolated validation service and exploring structured reports.
|
| 7 |
+
License: MIT + file LICENSE
|
| 8 |
+
Encoding: UTF-8
|
| 9 |
+
LazyData: true
|
| 10 |
+
Imports:
|
| 11 |
+
bslib,
|
| 12 |
+
config,
|
| 13 |
+
DT,
|
| 14 |
+
golem,
|
| 15 |
+
htmltools,
|
| 16 |
+
httr2,
|
| 17 |
+
jsonlite,
|
| 18 |
+
shiny,
|
| 19 |
+
shinyjs
|
| 20 |
+
Suggests:
|
| 21 |
+
testthat (>= 3.0.0)
|
| 22 |
+
Config/testthat/edition: 3
|
| 23 |
+
Roxygen: list(markdown = TRUE)
|
| 24 |
+
RoxygenNote: 7.3.2
|
golem/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 Project RxV
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
|
golem/NAMESPACE
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export(run_app)
|
| 2 |
+
import(shiny)
|
golem/R/app_server.R
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
app_server <- function(input, output, session) {
|
| 2 |
+
run_id <- mod_submit_server("submit")
|
| 3 |
+
mod_report_server("report", run_id)
|
| 4 |
+
}
|
golem/R/app_ui.R
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
app_ui <- function(request) {
|
| 2 |
+
bslib::page_navbar(
|
| 3 |
+
title = htmltools::tagList(htmltools::tags$span(class = "rxv-mark", "RxV"), " Project RxV"),
|
| 4 |
+
id = "main_nav",
|
| 5 |
+
theme = bslib::bs_theme(version = 5, bg = "#070A12", fg = "#F4F7FF", primary = "#8B5CF6", base_font = bslib::font_google("DM Sans")),
|
| 6 |
+
header = htmltools::tagList(
|
| 7 |
+
shinyjs::useShinyjs(),
|
| 8 |
+
htmltools::tags$link(rel = "stylesheet", href = "www/rxv.css"),
|
| 9 |
+
htmltools::tags$script(src = "www/rxv.js")
|
| 10 |
+
),
|
| 11 |
+
bslib::nav_panel("Validate", mod_submit_ui("submit")),
|
| 12 |
+
bslib::nav_panel("Report", mod_report_ui("report")),
|
| 13 |
+
bslib::nav_spacer(),
|
| 14 |
+
bslib::nav_item(htmltools::tags$span(class = "nav-status", htmltools::tags$i(class = "status-dot"), " Isolated runner")),
|
| 15 |
+
footer = htmltools::tags$footer(class = "rxv-footer", "Project RxV · Public R package validation · Code runs only in an ephemeral, no-egress sandbox")
|
| 16 |
+
)
|
| 17 |
+
}
|
golem/R/mod_report.R
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#' Live validation report UI
|
| 2 |
+
mod_report_ui <- function(id) {
|
| 3 |
+
ns <- shiny::NS(id)
|
| 4 |
+
htmltools::tagList(
|
| 5 |
+
htmltools::tags$section(class = "report-hero",
|
| 6 |
+
htmltools::tags$div(class = "eyebrow", "LIVE VALIDATION REPORT"),
|
| 7 |
+
htmltools::tags$h2(shiny::textOutput(ns("title"), inline = TRUE)),
|
| 8 |
+
htmltools::tags$div(class = "run-meta", shiny::uiOutput(ns("meta")))
|
| 9 |
+
),
|
| 10 |
+
shiny::uiOutput(ns("progress")),
|
| 11 |
+
bslib::layout_columns(
|
| 12 |
+
col_widths = c(4, 8),
|
| 13 |
+
bslib::card(class = "rxv-card score-card", shiny::uiOutput(ns("score"))),
|
| 14 |
+
bslib::card(class = "rxv-card", bslib::card_header("Validation suites"), shiny::uiOutput(ns("suites")))
|
| 15 |
+
),
|
| 16 |
+
bslib::card(class = "rxv-card findings-card", bslib::card_header("Findings"), DT::DTOutput(ns("findings")))
|
| 17 |
+
)
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
#' Live validation report server
|
| 21 |
+
mod_report_server <- function(id, run_id) {
|
| 22 |
+
shiny::moduleServer(id, function(input, output, session) {
|
| 23 |
+
result <- shiny::reactiveVal(NULL)
|
| 24 |
+
timer <- shiny::reactiveTimer(3000, session)
|
| 25 |
+
shiny::observe({
|
| 26 |
+
timer()
|
| 27 |
+
id <- run_id()
|
| 28 |
+
if (!is.null(id)) result(tryCatch(get_rxv_run(id), error = function(e) list(status = "unavailable", error = "Report service is unreachable.")))
|
| 29 |
+
})
|
| 30 |
+
output$title <- shiny::renderText({ if (is.null(run_id())) "Your next release starts here" else paste("Run", substr(run_id(), 1, 12)) })
|
| 31 |
+
output$meta <- shiny::renderUI({
|
| 32 |
+
r <- result(); if (is.null(r)) return(htmltools::tags$span("Submit a package to begin."))
|
| 33 |
+
htmltools::tagList(htmltools::tags$span(class = paste("status-pill", r$status), toupper(r$status)), htmltools::tags$span(" · "), htmltools::tags$span(r$source_ref %||% ""), htmltools::tags$span(" · "), htmltools::tags$span(toupper(r$profile %||% "")))
|
| 34 |
+
})
|
| 35 |
+
output$progress <- shiny::renderUI({
|
| 36 |
+
r <- result(); if (is.null(r) || r$status %in% c("passed", "failed", "error")) return(NULL)
|
| 37 |
+
htmltools::tags$div(class = "queue-progress", htmltools::tags$span(class = "pulse"), "Sandbox is preparing an isolated R environment. This report updates automatically.")
|
| 38 |
+
})
|
| 39 |
+
output$score <- shiny::renderUI({
|
| 40 |
+
report <- result()$report %||% NULL
|
| 41 |
+
if (is.null(report)) return(htmltools::tags$div(class = "empty-score", "Quality score will appear when validation completes."))
|
| 42 |
+
htmltools::tags$div(class = "score-content", htmltools::tags$span("RXV QUALITY SCORE"), htmltools::tags$strong(paste0(report$score %||% "—", "/100")), htmltools::tags$p(report$verdict %||% "Complete"), htmltools::tags$small("Score weights correctness, reproducibility, maintainability and release risk."))
|
| 43 |
+
})
|
| 44 |
+
output$suites <- shiny::renderUI({
|
| 45 |
+
suites <- result()$report$suites %||% list()
|
| 46 |
+
if (!length(suites)) return(htmltools::tags$p(class = "muted", "Suite results will arrive as the runner completes."))
|
| 47 |
+
htmltools::tags$div(class = "suite-list", lapply(suites, function(s) htmltools::tags$div(class = "suite-row", htmltools::tags$span(class = paste("suite-status", s$status), "●"), htmltools::tags$div(htmltools::tags$strong(s$name), htmltools::tags$small(s$summary)), htmltools::tags$span(class = "suite-state", toupper(s$status)))))
|
| 48 |
+
})
|
| 49 |
+
output$findings <- DT::renderDT({
|
| 50 |
+
rows <- result()$report$findings %||% list()
|
| 51 |
+
if (!length(rows)) return(DT::datatable(data.frame(Status = "No findings yet"), options = list(dom = "t"), rownames = FALSE))
|
| 52 |
+
table <- do.call(rbind, lapply(rows, function(x) data.frame(Severity = x$severity, Rule = x$rule, Location = paste0(x$file, ":", x$line), Finding = x$message, stringsAsFactors = FALSE)))
|
| 53 |
+
DT::datatable(table, options = list(pageLength = 6, dom = "tip"), rownames = FALSE, class = "compact")
|
| 54 |
+
})
|
| 55 |
+
})
|
| 56 |
+
}
|
golem/R/mod_submit.R
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#' Public submission module UI
|
| 2 |
+
mod_submit_ui <- function(id) {
|
| 3 |
+
ns <- shiny::NS(id)
|
| 4 |
+
htmltools::tagList(
|
| 5 |
+
htmltools::tags$section(class = "hero-shell",
|
| 6 |
+
htmltools::tags$div(class = "eyebrow", "R PACKAGE QUALITY INTELLIGENCE"),
|
| 7 |
+
htmltools::tags$h1("Prove your package is ready.", htmltools::tags$span("Before CRAN does.")),
|
| 8 |
+
htmltools::tags$p("Run a deep, isolated validation across package integrity, AST safety, unit tests, coverage, docs, visual snapshots, and reproducibility."),
|
| 9 |
+
htmltools::tags$div(class = "hero-metrics",
|
| 10 |
+
metric_card("9", "validation domains"), metric_card("0", "network access in test sandbox"), metric_card("3", "release profiles")
|
| 11 |
+
)
|
| 12 |
+
),
|
| 13 |
+
bslib::layout_columns(
|
| 14 |
+
col_widths = c(7, 5),
|
| 15 |
+
bslib::card(class = "rxv-card submit-card",
|
| 16 |
+
bslib::card_header(htmltools::tagList(htmltools::tags$span(class = "step-number", "01"), htmltools::tags$strong("Package source"), htmltools::tags$span(class = "muted", "Public GitHub or source ZIP"))),
|
| 17 |
+
shiny::radioButtons(ns("source_kind"), NULL, choices = c("GitHub repository" = "github", "Upload ZIP" = "zip"), selected = "github", inline = TRUE),
|
| 18 |
+
shiny::conditionalPanel(sprintf("input['%s'] === 'github'", ns("source_kind")),
|
| 19 |
+
shiny::textInput(ns("github_url"), "Public GitHub repository", placeholder = "https://github.com/org/package")
|
| 20 |
+
),
|
| 21 |
+
shiny::conditionalPanel(sprintf("input['%s'] === 'zip'", ns("source_kind")),
|
| 22 |
+
shiny::fileInput(ns("package_zip"), "Package source archive", accept = ".zip", buttonLabel = "Choose ZIP")
|
| 23 |
+
),
|
| 24 |
+
htmltools::tags$div(class = "drop-note", htmltools::tags$i(class = "shield-icon", "✦"), "Archives are screened before scheduling. Package code is never executed in this UI."),
|
| 25 |
+
shiny::actionButton(ns("submit"), htmltools::tagList("Start validation", htmltools::tags$span("→")), class = "btn-rxv")
|
| 26 |
+
),
|
| 27 |
+
bslib::card(class = "rxv-card profile-card",
|
| 28 |
+
bslib::card_header(htmltools::tagList(htmltools::tags$span(class = "step-number", "02"), htmltools::tags$strong("Validation depth"))),
|
| 29 |
+
shiny::radioButtons(ns("profile"), NULL, choices = c("Rapid · static + install + tests" = "rapid", "Standard · full package confidence" = "standard", "Release · visual + matrix + reproducibility" = "release"), selected = "standard"),
|
| 30 |
+
htmltools::tags$div(class = "profile-includes", htmltools::tags$span("STANDARD INCLUDES"), htmltools::tags$ul(htmltools::tags$li("R CMD check — as CRAN"), htmltools::tags$li("testthat, coverage, lint, docs"), htmltools::tags$li("AST policy and dependency audit")))
|
| 31 |
+
)
|
| 32 |
+
),
|
| 33 |
+
htmltools::tags$section(class = "matrix-section",
|
| 34 |
+
htmltools::tags$div(class = "section-label", "VALIDATION MATRIX"),
|
| 35 |
+
htmltools::tags$div(class = "matrix-grid",
|
| 36 |
+
matrix_tile("⌘", "Package integrity", "Build · install · check"), matrix_tile("◈", "AST intelligence", "Parse · complexity · risk"),
|
| 37 |
+
matrix_tile("✓", "Test confidence", "testthat · coverage"), matrix_tile("◉", "Visual regression", "vdiffr · Shiny"),
|
| 38 |
+
matrix_tile("¶", "Documentation", "Rd · roxygen · examples"), matrix_tile("↺", "Reproducibility", "renv · dependencies")
|
| 39 |
+
)
|
| 40 |
+
)
|
| 41 |
+
)
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
metric_card <- function(value, label) htmltools::tags$div(class = "metric", htmltools::tags$strong(value), htmltools::tags$span(label))
|
| 45 |
+
matrix_tile <- function(icon, title, description) htmltools::tags$div(class = "matrix-tile", htmltools::tags$span(class = "matrix-icon", icon), htmltools::tags$strong(title), htmltools::tags$small(description))
|
| 46 |
+
|
| 47 |
+
#' Submission module server
|
| 48 |
+
mod_submit_server <- function(id) {
|
| 49 |
+
shiny::moduleServer(id, function(input, output, session) {
|
| 50 |
+
submitted <- shiny::reactiveVal(NULL)
|
| 51 |
+
shiny::observeEvent(input$submit, {
|
| 52 |
+
github <- trimws(input$github_url %||% "")
|
| 53 |
+
zip <- input$package_zip$datapath %||% ""
|
| 54 |
+
if (identical(input$source_kind, "github") && !grepl("^https://github\\.com/[^/]+/[^/]+/?$", github)) {
|
| 55 |
+
shiny::showNotification("Enter a public github.com owner/repository URL.", type = "error"); return()
|
| 56 |
+
}
|
| 57 |
+
if (identical(input$source_kind, "zip") && !nzchar(zip)) {
|
| 58 |
+
shiny::showNotification("Choose a package ZIP file.", type = "error"); return()
|
| 59 |
+
}
|
| 60 |
+
shinyjs::disable("submit")
|
| 61 |
+
on.exit(shinyjs::enable("submit"), add = TRUE)
|
| 62 |
+
result <- tryCatch(submit_to_rxv(github, zip, input$profile), error = function(e) e)
|
| 63 |
+
if (inherits(result, "error")) {
|
| 64 |
+
shiny::showNotification("Could not schedule validation. Please try again.", type = "error")
|
| 65 |
+
} else {
|
| 66 |
+
submitted(result$id)
|
| 67 |
+
shiny::showNotification("Validation queued — opening live report.", type = "message")
|
| 68 |
+
shiny::updateNavbarPage(session, "main_nav", selected = "Report")
|
| 69 |
+
}
|
| 70 |
+
})
|
| 71 |
+
submitted
|
| 72 |
+
})
|
| 73 |
+
}
|
golem/R/run_app.R
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#' Run the Project RxV Golem application
|
| 2 |
+
#'
|
| 3 |
+
#' @param ... Arguments passed to [shiny::shinyApp()].
|
| 4 |
+
#' @export
|
| 5 |
+
run_app <- function(...) {
|
| 6 |
+
shiny::addResourcePath("www", app_sys("app/www"))
|
| 7 |
+
shiny::shinyApp(ui = app_ui, server = app_server, ...)
|
| 8 |
+
}
|
golem/R/service.R
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
rxv_api_url <- function() {
|
| 2 |
+
Sys.getenv("RXV_API_URL", "http://api:7860")
|
| 3 |
+
}
|
| 4 |
+
|
| 5 |
+
rxv_api <- function(path) paste0(sub("/$", "", rxv_api_url()), path)
|
| 6 |
+
|
| 7 |
+
submit_to_rxv <- function(github_url, zip_path, profile) {
|
| 8 |
+
req <- httr2::request(rxv_api("/api/submissions")) |>
|
| 9 |
+
httr2::req_method("POST") |>
|
| 10 |
+
httr2::req_timeout(30)
|
| 11 |
+
if (nzchar(github_url)) {
|
| 12 |
+
req <- httr2::req_body_multipart(req, github_url = github_url, profile = profile)
|
| 13 |
+
} else {
|
| 14 |
+
req <- httr2::req_body_multipart(req, package_zip = httr2::form_file(zip_path), profile = profile)
|
| 15 |
+
}
|
| 16 |
+
response <- httr2::req_perform(req)
|
| 17 |
+
httr2::resp_body_json(response, simplifyVector = FALSE)
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
get_rxv_run <- function(run_id) {
|
| 21 |
+
response <- httr2::request(rxv_api(paste0("/api/runs/", run_id))) |>
|
| 22 |
+
httr2::req_timeout(15) |>
|
| 23 |
+
httr2::req_perform()
|
| 24 |
+
httr2::resp_body_json(response, simplifyVector = FALSE)
|
| 25 |
+
}
|
golem/R/utils.R
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
`%||%` <- function(x, y) if (is.null(x) || !length(x)) y else x
|
| 2 |
+
|
| 3 |
+
app_sys <- function(...) system.file(..., package = "rxv")
|
golem/inst/app/www/rxv.css
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
:root { --ink:#070a12; --panel:#101624; --panel-hi:#151d2e; --text:#f4f7ff; --muted:#8e9ab5; --violet:#9e7bff; --cyan:#55e6d2; --line:#263047; --danger:#ff687c; }
|
| 2 |
+
body { background: radial-gradient(900px 500px at 82% -8%, rgba(112,74,255,.28), transparent 56%), var(--ink); letter-spacing:.01em; }
|
| 3 |
+
.navbar { background:rgba(7,10,18,.75)!important; border-bottom:1px solid rgba(142,154,181,.15); backdrop-filter:blur(18px); padding:.85rem 7%; }
|
| 4 |
+
.navbar-brand { color:var(--text)!important; font-weight:700; letter-spacing:.02em; }.rxv-mark{ display:inline-grid; place-items:center; width:2rem; height:2rem; margin-right:.5rem; border-radius:8px; background:linear-gradient(135deg,#a88bff,#5f53f7); color:#fff; font-size:.8rem; }
|
| 5 |
+
.nav-link,.navbar-nav .nav-link { color:var(--muted)!important; }.nav-link.active{color:var(--text)!important}.nav-status{ color:#c8d1e7; font-size:.82rem; padding:.5rem; }.status-dot{ display:inline-block; width:7px; height:7px; border-radius:50%; background:var(--cyan); box-shadow:0 0 12px var(--cyan); margin-right:.45rem; }
|
| 6 |
+
.container-fluid { max-width:1280px; padding:0 5%; }.hero-shell,.report-hero{ padding:5.6rem 0 2.6rem; max-width:850px; }.eyebrow,.section-label{ color:var(--cyan); font-size:.7rem; font-weight:800; letter-spacing:.18em; }.hero-shell h1{font-size:clamp(2.7rem,6vw,5.45rem);line-height:.98;letter-spacing:-.055em;margin:.85rem 0 1.2rem;font-weight:800}.hero-shell h1 span{display:block;color:#a98cff}.hero-shell p{max-width:700px;color:#abb6ce;font-size:1.1rem;line-height:1.65}.hero-metrics{display:flex;gap:2.4rem;margin-top:2.1rem}.metric{display:grid;gap:.15rem}.metric strong{font-size:1.55rem;color:#fff}.metric span{font-size:.76rem;color:var(--muted);text-transform:uppercase;letter-spacing:.08em}
|
| 7 |
+
.rxv-card{background:linear-gradient(145deg,rgba(21,29,46,.96),rgba(12,17,28,.96))!important;border:1px solid var(--line)!important;border-radius:15px!important;color:var(--text);box-shadow:0 18px 55px rgba(0,0,0,.16)}.card-header{background:transparent!important;border-bottom:1px solid rgba(142,154,181,.13)!important;padding:1.2rem 1.35rem!important}.card-body{padding:1.35rem!important}.step-number{font-family:monospace;color:var(--cyan);margin-right:.7rem}.muted{color:var(--muted);font-size:.83rem;margin-left:.5rem}.form-control,.form-select{background:#0b101b!important;color:var(--text)!important;border-color:#2b3852!important;padding:.8rem!important}.form-control:focus{box-shadow:0 0 0 .18rem rgba(158,123,255,.22)!important}.radio{margin-bottom:.85rem}.radio label{color:#c6d0e5;margin-left:.3rem}.drop-note{padding:.85rem 1rem;background:rgba(85,230,210,.06);border:1px solid rgba(85,230,210,.14);border-radius:9px;color:#a9dcd7;font-size:.82rem}.shield-icon{color:var(--cyan);padding-right:.45rem}.btn-rxv{margin-top:1.25rem;width:100%;padding:.85rem 1.1rem;border:0;border-radius:8px;background:linear-gradient(90deg,#8a62f7,#a27cff);color:white;font-weight:700;box-shadow:0 8px 25px rgba(138,98,247,.3)}.btn-rxv:hover{filter:brightness(1.15);color:#fff}.profile-includes{margin-top:1.1rem;padding-top:1rem;border-top:1px solid var(--line);color:#abb6ce;font-size:.84rem}.profile-includes span{font-size:.66rem;letter-spacing:.12em;color:var(--cyan)}.profile-includes ul{margin: .55rem 0 0;padding-left:1rem;line-height:1.9}
|
| 8 |
+
.matrix-section{padding:3.7rem 0}.matrix-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:.75rem;margin-top:1rem}.matrix-tile{min-height:125px;border:1px solid #202b42;background:rgba(16,22,36,.57);padding:1rem;border-radius:12px;display:grid;align-content:start;gap:.3rem}.matrix-tile:hover{border-color:#795ee7;transform:translateY(-2px);transition:.2s}.matrix-icon{color:var(--cyan);font-size:1.25rem}.matrix-tile strong{font-size:.92rem}.matrix-tile small{color:var(--muted)}
|
| 9 |
+
.report-hero{padding-bottom:1.5rem}.report-hero h2{font-weight:750;margin:.55rem 0}.run-meta{color:var(--muted)}.status-pill{font-size:.65rem;letter-spacing:.1em;padding:.3rem .55rem;border-radius:99px;background:#25314b;color:#d9e1f3}.status-pill.passed{background:rgba(85,230,210,.12);color:var(--cyan)}.status-pill.error,.status-pill.failed{background:rgba(255,104,124,.12);color:#ff98a6}.queue-progress{margin-bottom:1rem;padding:.85rem 1rem;background:rgba(158,123,255,.09);color:#ded4ff;border:1px solid rgba(158,123,255,.22);border-radius:9px}.pulse{display:inline-block;width:8px;height:8px;border-radius:50%;background:#ab8aff;margin-right:.5rem;animation:pulse 1s infinite}@keyframes pulse{50%{opacity:.25;transform:scale(.75)}}.score-content{display:grid;gap:.35rem}.score-content>span{font-size:.7rem;color:var(--cyan);letter-spacing:.12em}.score-content strong{font-size:4rem;line-height:1;font-weight:800}.score-content p{margin:0;color:#cbbdff;text-transform:uppercase;font-size:.75rem;letter-spacing:.12em}.score-content small{color:var(--muted);line-height:1.55;margin-top:.6rem}.suite-list{display:grid;gap:.85rem}.suite-row{display:grid;grid-template-columns:auto 1fr auto;gap:.75rem;align-items:start;padding-bottom:.85rem;border-bottom:1px solid rgba(142,154,181,.11)}.suite-row:last-child{border:0;padding-bottom:0}.suite-row small{display:block;color:var(--muted);margin-top:.18rem}.suite-status.passed{color:var(--cyan)}.suite-status.warning{color:#ffc766}.suite-status.failed{color:var(--danger)}.suite-status.skipped{color:var(--muted)}.suite-state{font-size:.65rem;letter-spacing:.09em;color:var(--muted)}.findings-card{margin:1.2rem 0 3rem}.dataTables_wrapper,.dataTables_info,.dataTables_paginate{color:#bec8dc!important}.table{color:#d8e0ef!important;border-color:var(--line)!important}.table>thead{color:var(--cyan)!important}.table>tbody>tr>td{background:transparent!important;color:#d8e0ef!important;border-color:var(--line)!important}.rxv-footer{border-top:1px solid var(--line);color:var(--muted);font-size:.75rem;padding:1.4rem 5%;text-align:center}
|
| 10 |
+
@media(max-width:700px){.hero-shell{padding-top:3.7rem}.hero-metrics{gap:1rem;flex-wrap:wrap}.matrix-grid{grid-template-columns:1fr 1fr}.navbar{padding: .75rem 5%}}
|
golem/inst/app/www/rxv.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
document.addEventListener("DOMContentLoaded", () => {
|
| 2 |
+
document.documentElement.classList.add("rxv-ready");
|
| 3 |
+
});
|
runner/Dockerfile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM rocker/r-ver:4.4.2
|
| 2 |
+
ENV DEBIAN_FRONTEND=noninteractive RENV_CONFIG_REPOS_OVERRIDE=https://packagemanager.posit.co/cran/latest
|
| 3 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 4 |
+
git ca-certificates pandoc libcurl4-openssl-dev libssl-dev libxml2-dev libfontconfig1-dev \
|
| 5 |
+
libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev \
|
| 6 |
+
chromium fonts-liberation python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
| 7 |
+
RUN R -q -e "install.packages(c('jsonlite','testthat','tinytest','RUnit','covr','lintr','cyclocomp','rcmdcheck','roxygen2','pkgload','goodpractice','vdiffr','shinytest2','renv','spelling','urlchecker','pkgdown'), Ncpus=2)"
|
| 8 |
+
WORKDIR /srv/runner
|
| 9 |
+
COPY requirements.txt ./
|
| 10 |
+
RUN pip3 install --break-system-packages --no-cache-dir -r requirements.txt && useradd --create-home --uid 10001 rxv
|
| 11 |
+
COPY service.py validate.R ./
|
| 12 |
+
RUN mkdir -p /data/uploads /data/reports /var/lib/rxv && chown -R rxv:rxv /srv/runner /data /var/lib/rxv
|
| 13 |
+
USER rxv
|
| 14 |
+
EXPOSE 8081
|
| 15 |
+
CMD ["uvicorn", "service:app", "--host", "0.0.0.0", "--port", "8081"]
|
runner/requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi==0.115.6
|
| 2 |
+
uvicorn[standard]==0.34.0
|
| 3 |
+
httpx==0.28.1
|
| 4 |
+
pydantic==2.10.5
|
runner/service.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Development runner for Project RxV.
|
| 2 |
+
|
| 3 |
+
Production implementations must replace `execute_job` with a job provider that
|
| 4 |
+
starts a new egress-denied, non-privileged container/VM for every job. The API
|
| 5 |
+
contract remains the same.
|
| 6 |
+
"""
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import asyncio
|
| 10 |
+
import json
|
| 11 |
+
import os
|
| 12 |
+
import re
|
| 13 |
+
import shutil
|
| 14 |
+
import subprocess
|
| 15 |
+
import tempfile
|
| 16 |
+
import time
|
| 17 |
+
import zipfile
|
| 18 |
+
from pathlib import Path
|
| 19 |
+
|
| 20 |
+
import httpx
|
| 21 |
+
from fastapi import FastAPI, Header, HTTPException
|
| 22 |
+
from pydantic import BaseModel, Field
|
| 23 |
+
|
| 24 |
+
TOKEN = os.environ.get("RXV_RUNNER_TOKEN", "")
|
| 25 |
+
UPLOAD_ROOT = Path(os.environ.get("RXV_UPLOAD_ROOT", "/data/uploads")).resolve()
|
| 26 |
+
REPORT_ROOT = Path(os.environ.get("RXV_REPORT_ROOT", "/data/reports")).resolve()
|
| 27 |
+
JOB_SEMAPHORE = asyncio.Semaphore(int(os.environ.get("RXV_MAX_CONCURRENT_JOBS", "1")))
|
| 28 |
+
GITHUB_RE = re.compile(r"^https://github\.com/[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$")
|
| 29 |
+
|
| 30 |
+
app = FastAPI(title="Project RxV Runner", docs_url=None, redoc_url=None)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class Source(BaseModel):
|
| 34 |
+
type: str
|
| 35 |
+
url: str | None = None
|
| 36 |
+
artifact_path: str | None = None
|
| 37 |
+
filename: str | None = None
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class Job(BaseModel):
|
| 41 |
+
run_id: str = Field(pattern=r"^[a-f0-9]{32}$")
|
| 42 |
+
source: Source
|
| 43 |
+
profile: str = Field(pattern=r"^(rapid|standard|release)$")
|
| 44 |
+
callback_url: str
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def auth(authorization: str | None) -> None:
|
| 48 |
+
if not TOKEN or authorization != f"Bearer {TOKEN}":
|
| 49 |
+
raise HTTPException(401, "unauthorized")
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def safe_unzip(archive: Path, target: Path) -> None:
|
| 53 |
+
with zipfile.ZipFile(archive) as zf:
|
| 54 |
+
infos = zf.infolist()
|
| 55 |
+
if len(infos) > 10_000 or sum(i.file_size for i in infos) > 2_000_000_000:
|
| 56 |
+
raise ValueError("archive exceeds limits")
|
| 57 |
+
for info in infos:
|
| 58 |
+
destination = (target / info.filename).resolve()
|
| 59 |
+
if not destination.is_relative_to(target.resolve()) or info.is_dir() is False and info.filename.endswith("/"):
|
| 60 |
+
raise ValueError("unsafe archive path")
|
| 61 |
+
zf.extractall(target)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def package_directory(root: Path) -> Path:
|
| 65 |
+
descriptions = list(root.rglob("DESCRIPTION"))
|
| 66 |
+
if len(descriptions) != 1:
|
| 67 |
+
raise ValueError("source must contain exactly one package DESCRIPTION file")
|
| 68 |
+
return descriptions[0].parent
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def acquire_source(source: Source, workspace: Path) -> Path:
|
| 72 |
+
source_root = workspace / "source"
|
| 73 |
+
source_root.mkdir()
|
| 74 |
+
if source.type == "github":
|
| 75 |
+
if not source.url or not GITHUB_RE.fullmatch(source.url):
|
| 76 |
+
raise ValueError("invalid GitHub source")
|
| 77 |
+
# Fetch is intentionally the only networked stage. Production uses a URL broker
|
| 78 |
+
# that pins the resulting commit SHA before the isolated run begins.
|
| 79 |
+
subprocess.run(["git", "clone", "--depth", "1", source.url, str(source_root / "repo")], check=True, timeout=90, capture_output=True, text=True)
|
| 80 |
+
elif source.type == "zip":
|
| 81 |
+
if not source.artifact_path:
|
| 82 |
+
raise ValueError("missing archive")
|
| 83 |
+
archive = Path(source.artifact_path).resolve()
|
| 84 |
+
if not archive.is_relative_to(UPLOAD_ROOT) or not archive.is_file():
|
| 85 |
+
raise ValueError("archive is outside the approved store")
|
| 86 |
+
safe_unzip(archive, source_root)
|
| 87 |
+
else:
|
| 88 |
+
raise ValueError("unsupported source type")
|
| 89 |
+
return package_directory(source_root)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def execute_job_sync(job: Job) -> dict:
|
| 93 |
+
REPORT_ROOT.mkdir(parents=True, exist_ok=True)
|
| 94 |
+
with tempfile.TemporaryDirectory(prefix=f"rxv-{job.run_id[:8]}-", dir="/var/lib/rxv") as tmp:
|
| 95 |
+
workspace = Path(tmp)
|
| 96 |
+
package = acquire_source(job.source, workspace)
|
| 97 |
+
report = REPORT_ROOT / f"{job.run_id}.json"
|
| 98 |
+
environment = {"HOME": str(workspace / "home"), "R_DEFAULT_PACKAGES": "stats,graphics,grDevices,utils,datasets,methods,base", "NO_PROXY": "*"}
|
| 99 |
+
(workspace / "home").mkdir()
|
| 100 |
+
completed = subprocess.run(
|
| 101 |
+
["Rscript", "--vanilla", "/srv/runner/validate.R", str(package), str(report), job.profile],
|
| 102 |
+
cwd=workspace, env={**os.environ, **environment}, timeout={"rapid": 600, "standard": 1200, "release": 2400}[job.profile],
|
| 103 |
+
text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
| 104 |
+
)
|
| 105 |
+
if not report.exists():
|
| 106 |
+
raise RuntimeError(f"validator did not produce a report (exit {completed.returncode})")
|
| 107 |
+
result = json.loads(report.read_text(encoding="utf-8"))
|
| 108 |
+
result["runner_stdout_tail"] = completed.stdout[-6000:]
|
| 109 |
+
report.write_text(json.dumps(result), encoding="utf-8")
|
| 110 |
+
return result
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
async def execute_job(job: Job) -> None:
|
| 114 |
+
async with JOB_SEMAPHORE:
|
| 115 |
+
try:
|
| 116 |
+
report = await asyncio.to_thread(execute_job_sync, job)
|
| 117 |
+
statuses = [x.get("status") for x in report.get("suites", [])]
|
| 118 |
+
status = "failed" if "failed" in statuses else "passed"
|
| 119 |
+
payload = {"status": status, "report": report}
|
| 120 |
+
except Exception as exc:
|
| 121 |
+
payload = {"status": "error", "error": "The isolated runner could not complete this validation."}
|
| 122 |
+
async with httpx.AsyncClient(timeout=30) as client:
|
| 123 |
+
await client.post(job.callback_url, json=payload, headers={"Authorization": f"Bearer {TOKEN}"})
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
@app.post("/jobs", status_code=202)
|
| 127 |
+
async def create_job(job: Job, authorization: str | None = Header(default=None)) -> dict:
|
| 128 |
+
auth(authorization)
|
| 129 |
+
asyncio.create_task(execute_job(job))
|
| 130 |
+
return {"accepted": True, "run_id": job.run_id}
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
@app.get("/health")
|
| 134 |
+
async def health() -> dict:
|
| 135 |
+
return {"service": "rxv-runner", "status": "ok", "mode": "development-adapter"}
|
runner/validate.R
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env Rscript
|
| 2 |
+
# Project RxV validation engine. This script runs only inside a disposable sandbox.
|
| 3 |
+
|
| 4 |
+
args <- commandArgs(trailingOnly = TRUE)
|
| 5 |
+
if (length(args) != 3) stop("usage: validate.R <package-dir> <report.json> <profile>")
|
| 6 |
+
package_dir <- normalizePath(args[[1]], mustWork = TRUE)
|
| 7 |
+
report_path <- args[[2]]
|
| 8 |
+
profile <- args[[3]]
|
| 9 |
+
|
| 10 |
+
`%||%` <- function(x, y) if (is.null(x) || !length(x)) y else x
|
| 11 |
+
suites <- list(); findings <- list(); command_logs <- list()
|
| 12 |
+
|
| 13 |
+
add_finding <- function(severity, rule, file, line, message) {
|
| 14 |
+
findings[[length(findings) + 1]] <<- list(severity = severity, rule = rule, file = file, line = as.integer(line %||% 0), message = message)
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
add_suite <- function(name, status, summary, detail = NULL) {
|
| 18 |
+
suites[[length(suites) + 1]] <<- list(name = name, status = status, summary = summary, detail = detail)
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
run_command <- function(name, command, args, timeout_note = NULL) {
|
| 22 |
+
output <- tryCatch(system2(command, args, stdout = TRUE, stderr = TRUE), error = function(e) structure(conditionMessage(e), status = 127L))
|
| 23 |
+
code <- attr(output, "status") %||% 0L
|
| 24 |
+
command_logs[[name]] <<- list(exit_code = as.integer(code), output_tail = tail(output, 80), timeout_note = timeout_note)
|
| 25 |
+
list(ok = identical(as.integer(code), 0L), output = output, code = code)
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
with_suite <- function(name, fn) {
|
| 29 |
+
tryCatch(fn(), error = function(e) {
|
| 30 |
+
add_suite(name, "failed", paste("Could not complete:", conditionMessage(e)))
|
| 31 |
+
add_finding("high", "RXV-RUN-001", "", 0, paste(name, "failed:", conditionMessage(e)))
|
| 32 |
+
})
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
description <- tryCatch(read.dcf(file.path(package_dir, "DESCRIPTION"))[1, , drop = TRUE], error = function(e) character())
|
| 36 |
+
pkg_name <- unname(description[["Package"]] %||% basename(package_dir))
|
| 37 |
+
r_files <- list.files(file.path(package_dir, "R"), pattern = "\\.[Rr]$", full.names = TRUE, recursive = TRUE)
|
| 38 |
+
all_source_files <- list.files(package_dir, recursive = TRUE, full.names = TRUE, all.files = FALSE)
|
| 39 |
+
|
| 40 |
+
with_suite("Package structure", function() {
|
| 41 |
+
required <- c("DESCRIPTION", "NAMESPACE", "R")
|
| 42 |
+
missing <- required[!file.exists(file.path(package_dir, required))]
|
| 43 |
+
source_files <- length(r_files)
|
| 44 |
+
test_frameworks <- c(
|
| 45 |
+
if (dir.exists(file.path(package_dir, "tests", "testthat"))) "testthat",
|
| 46 |
+
if (dir.exists(file.path(package_dir, "inst", "tinytest")) || dir.exists(file.path(package_dir, "tests", "tinytest"))) "tinytest",
|
| 47 |
+
if (dir.exists(file.path(package_dir, "inst", "unitTests"))) "RUnit"
|
| 48 |
+
)
|
| 49 |
+
if (length(missing) || !source_files) {
|
| 50 |
+
add_suite("Package structure", "failed", paste(c(if (length(missing)) paste("Missing:", paste(missing, collapse = ", ")), if (!source_files) "No R source files found"), collapse = "; "))
|
| 51 |
+
for (item in missing) add_finding("high", "RXV-STRUCT-001", item, 0, "Required package component is missing.")
|
| 52 |
+
} else {
|
| 53 |
+
add_suite("Package structure", "passed", paste(source_files, "R source file(s); test framework(s):", if (length(test_frameworks)) paste(test_frameworks, collapse = ", ") else "none detected"))
|
| 54 |
+
}
|
| 55 |
+
})
|
| 56 |
+
|
| 57 |
+
with_suite("Metadata, license & repository hygiene", function() {
|
| 58 |
+
warnings <- character()
|
| 59 |
+
if (!nzchar(description[["URL"]] %||% "")) warnings <- c(warnings, "URL field is not declared")
|
| 60 |
+
if (!nzchar(description[["BugReports"]] %||% "")) warnings <- c(warnings, "BugReports field is not declared")
|
| 61 |
+
license <- description[["License"]] %||% ""
|
| 62 |
+
if (!nzchar(license) || grepl("^file LICENSE$", license, ignore.case = TRUE) && !file.exists(file.path(package_dir, "LICENSE"))) {
|
| 63 |
+
warnings <- c(warnings, "License is absent or refers to a missing LICENSE file")
|
| 64 |
+
add_finding("medium", "RXV-META-003", "DESCRIPTION", 0, "Declare a valid, redistributable package license.")
|
| 65 |
+
}
|
| 66 |
+
if (!file.exists(file.path(package_dir, "README.md"))) warnings <- c(warnings, "README.md is missing")
|
| 67 |
+
if (!file.exists(file.path(package_dir, "NEWS.md")) && !file.exists(file.path(package_dir, "NEWS"))) warnings <- c(warnings, "NEWS is missing")
|
| 68 |
+
ignored <- file.path(package_dir, ".Rbuildignore")
|
| 69 |
+
if (file.exists(ignored) && any(grepl("^\\.git$", readLines(ignored, warn = FALSE)))) warnings <- c(warnings, ".Rbuildignore may not exclude all VCS metadata")
|
| 70 |
+
if (length(warnings)) add_suite("Metadata, license & repository hygiene", "warning", paste(warnings, collapse = "; "))
|
| 71 |
+
else add_suite("Metadata, license & repository hygiene", "passed", "Metadata, license declaration, README, NEWS, and build-ignore policy are present.")
|
| 72 |
+
})
|
| 73 |
+
|
| 74 |
+
with_suite("Package integrity", function() {
|
| 75 |
+
problems <- character()
|
| 76 |
+
required <- c("Package", "Version", "Title", "Description", "License", "Encoding")
|
| 77 |
+
missing <- required[!required %in% names(description) | !nzchar(description[required])]
|
| 78 |
+
if (length(missing)) problems <- c(problems, paste("DESCRIPTION missing:", paste(missing, collapse = ", ")))
|
| 79 |
+
if (!file.exists(file.path(package_dir, "NAMESPACE"))) problems <- c(problems, "NAMESPACE is missing")
|
| 80 |
+
build <- run_command("build", "R", c("CMD", "build", package_dir))
|
| 81 |
+
if (!build$ok) problems <- c(problems, "R CMD build failed")
|
| 82 |
+
lib <- file.path(tempdir(), "rxv-library"); dir.create(lib, showWarnings = FALSE)
|
| 83 |
+
install <- run_command("install", "R", c("CMD", "INSTALL", "--library", lib, package_dir))
|
| 84 |
+
if (!install$ok) problems <- c(problems, "Clean package install failed")
|
| 85 |
+
if (length(problems)) {
|
| 86 |
+
add_suite("Package integrity", "failed", paste(problems, collapse = "; "))
|
| 87 |
+
for (p in problems) add_finding("high", "RXV-PKG-001", "DESCRIPTION", 0, p)
|
| 88 |
+
} else add_suite("Package integrity", "passed", "DESCRIPTION, build, and clean installation completed.")
|
| 89 |
+
})
|
| 90 |
+
|
| 91 |
+
with_suite("AST & security", function() {
|
| 92 |
+
parse_errors <- character(); risky <- c("system", "system2", "shell", "shell.exec", "download.file", "url", "socketConnection", "eval", "parse", "source")
|
| 93 |
+
call_count <- 0L
|
| 94 |
+
for (file in r_files) {
|
| 95 |
+
parsed <- tryCatch(parse(file, keep.source = TRUE), error = function(e) e)
|
| 96 |
+
if (inherits(parsed, "error")) {
|
| 97 |
+
parse_errors <- c(parse_errors, sprintf("%s: %s", basename(file), conditionMessage(parsed)))
|
| 98 |
+
add_finding("high", "RXV-AST-001", sub(paste0("^", package_dir, "/?"), "", file), 0, conditionMessage(parsed)); next
|
| 99 |
+
}
|
| 100 |
+
tokens <- tryCatch(utils::getParseData(parsed), error = function(e) NULL)
|
| 101 |
+
if (!is.null(tokens)) {
|
| 102 |
+
calls <- tokens[tokens$token == "SYMBOL_FUNCTION_CALL", , drop = FALSE]
|
| 103 |
+
call_count <- call_count + nrow(calls)
|
| 104 |
+
flagged <- calls[calls$text %in% risky, , drop = FALSE]
|
| 105 |
+
for (i in seq_len(nrow(flagged))) add_finding("medium", "RXV-AST-004", sub(paste0("^", package_dir, "/?"), "", file), flagged$line1[[i]], paste0(flagged$text[[i]], "() requires a sandbox-policy review."))
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
dynamic_sources <- grep("(source|download\\.file)\\s*\\(\\s*['\"]https?://", unlist(lapply(r_files, readLines, warn = FALSE)), value = TRUE)
|
| 109 |
+
if (length(dynamic_sources)) add_finding("high", "RXV-AST-007", "R/", 0, "Remote source loading was detected and is blocked by production policy.")
|
| 110 |
+
if (length(parse_errors)) add_suite("AST & security", "failed", paste(length(parse_errors), "R file(s) could not be parsed."))
|
| 111 |
+
else if (any(vapply(findings, function(x) x$rule == "RXV-AST-004", logical(1)))) add_suite("AST & security", "warning", paste("Parsed", length(r_files), "R files and found", call_count, "function calls; review flagged process/network/dynamic-evaluation calls."))
|
| 112 |
+
else add_suite("AST & security", "passed", paste("Parsed", length(r_files), "R files and", call_count, "function calls with no policy-sensitive calls."))
|
| 113 |
+
})
|
| 114 |
+
|
| 115 |
+
with_suite("Secrets, supply-chain & unsafe-content scan", function() {
|
| 116 |
+
scan_files <- all_source_files[!grepl("(^|/)(renv/library|\\.git|node_modules)(/|$)", all_source_files)]
|
| 117 |
+
rules <- list(
|
| 118 |
+
"RXV-SEC-001" = "AKIA[0-9A-Z]{16}",
|
| 119 |
+
"RXV-SEC-002" = "gh[pousr]_[A-Za-z0-9_]{20,}",
|
| 120 |
+
"RXV-SEC-003" = "(?i)(api[_-]?key|secret|access[_-]?token|password)\\s*(<-|=|:)\\s*['\\\"][^'\\\"]{8,}",
|
| 121 |
+
"RXV-SEC-004" = "(?i)(curl|wget)\\s+https?://"
|
| 122 |
+
)
|
| 123 |
+
hits <- 0L
|
| 124 |
+
for (file in scan_files) {
|
| 125 |
+
if (file.info(file)$size > 2e6 || grepl("\\.(png|jpg|jpeg|pdf|rds|rda|zip|tar\\.gz)$", file, ignore.case = TRUE)) next
|
| 126 |
+
content <- tryCatch(readLines(file, warn = FALSE, encoding = "UTF-8"), error = function(e) character())
|
| 127 |
+
if (!length(content)) next
|
| 128 |
+
for (rule in names(rules)) {
|
| 129 |
+
matched <- grep(rules[[rule]], content, perl = TRUE, ignore.case = FALSE)
|
| 130 |
+
for (line in matched) {
|
| 131 |
+
hits <- hits + 1L
|
| 132 |
+
add_finding("high", rule, sub(paste0("^", package_dir, "/?"), "", file), line, "Potential credential, token, or shell-download command detected; remove or move to a secret manager.")
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
if (hits) add_suite("Secrets, supply-chain & unsafe-content scan", "failed", paste(hits, "high-risk content match(es) detected."))
|
| 137 |
+
else add_suite("Secrets, supply-chain & unsafe-content scan", "passed", "No common credential, token, or shell-download patterns were detected in text assets.")
|
| 138 |
+
})
|
| 139 |
+
|
| 140 |
+
with_suite("Maintainability & complexity", function() {
|
| 141 |
+
branch_total <- 0L; long_lines <- 0L; oversized <- character()
|
| 142 |
+
for (file in r_files) {
|
| 143 |
+
expr <- tryCatch(parse(file, keep.source = TRUE), error = function(e) NULL)
|
| 144 |
+
tokens <- if (!is.null(expr)) tryCatch(utils::getParseData(expr), error = function(e) NULL) else NULL
|
| 145 |
+
if (!is.null(tokens)) branch_total <- branch_total + sum(tokens$token %in% c("IF", "FOR", "WHILE", "REPEAT", "AND", "OR", "AND2", "OR2"))
|
| 146 |
+
lines <- tryCatch(readLines(file, warn = FALSE), error = function(e) character())
|
| 147 |
+
long_lines <- long_lines + sum(nchar(lines, type = "width") > 120)
|
| 148 |
+
if (length(lines) > 600) oversized <- c(oversized, basename(file))
|
| 149 |
+
}
|
| 150 |
+
summary <- paste(branch_total, "decision point(s)", "·", long_lines, "line(s) over 120 columns")
|
| 151 |
+
if (branch_total > 120 || long_lines > 20 || length(oversized)) {
|
| 152 |
+
add_suite("Maintainability & complexity", "warning", paste(summary, if (length(oversized)) paste("· oversized file(s):", paste(oversized, collapse = ", ")) else ""))
|
| 153 |
+
add_finding("low", "RXV-MAINT-001", "R/", 0, "Consider decomposing complex functions and long source files; inspect the complexity metrics in the report.")
|
| 154 |
+
} else add_suite("Maintainability & complexity", "passed", summary)
|
| 155 |
+
})
|
| 156 |
+
|
| 157 |
+
with_suite("Dependency compatibility", function() {
|
| 158 |
+
fields <- c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")
|
| 159 |
+
raw <- paste(unname(description[intersect(names(description), fields)]), collapse = ",")
|
| 160 |
+
deps <- trimws(gsub("\\s*\\([^)]*\\)", "", unlist(strsplit(raw, ",", fixed = TRUE))))
|
| 161 |
+
deps <- deps[nzchar(deps) & !deps %in% c("R", "base", "methods", "stats", "utils", "graphics", "grDevices", "datasets")]
|
| 162 |
+
unavailable <- deps[!vapply(deps, requireNamespace, quietly = TRUE, FUN.VALUE = logical(1))]
|
| 163 |
+
remotes <- description[["Remotes"]] %||% ""
|
| 164 |
+
if (length(unavailable)) {
|
| 165 |
+
add_suite("Dependency compatibility", "warning", paste("Runner image does not include:", paste(unavailable, collapse = ", "), ". A production dependency-preflight worker should resolve these from the approved package snapshot."))
|
| 166 |
+
add_finding("medium", "RXV-DEP-001", "DESCRIPTION", 0, "One or more declared dependencies are unavailable in the validation image.")
|
| 167 |
+
} else if (length(deps) || nzchar(remotes)) add_suite("Dependency compatibility", "passed", paste(length(deps), "declared dependency/dependencies available in the runner image."))
|
| 168 |
+
else add_suite("Dependency compatibility", "warning", "No Imports, Depends, Suggests, LinkingTo, or Remotes fields were declared.")
|
| 169 |
+
})
|
| 170 |
+
|
| 171 |
+
if (profile %in% c("standard", "release")) with_suite("CRAN readiness", function() {
|
| 172 |
+
tarballs <- list.files(getwd(), pattern = "\\.tar\\.gz$", full.names = TRUE)
|
| 173 |
+
if (!length(tarballs)) {
|
| 174 |
+
add_suite("CRAN readiness", "failed", "No package tarball was produced; R CMD check could not run."); return()
|
| 175 |
+
}
|
| 176 |
+
check <- run_command("check", "R", c("CMD", "check", "--as-cran", "--no-manual", tail(tarballs, 1)))
|
| 177 |
+
check_dir <- list.files(dirname(tarballs[[1]]), pattern = "\\.Rcheck$", full.names = TRUE)
|
| 178 |
+
check_log <- if (length(check_dir)) file.path(check_dir[[1]], "00check.log") else ""
|
| 179 |
+
text <- if (file.exists(check_log)) readLines(check_log, warn = FALSE) else check$output
|
| 180 |
+
notes <- grep("^(NOTE|WARNING|ERROR)", text, value = TRUE)
|
| 181 |
+
if (!check$ok || any(grepl("^ERROR", notes))) {
|
| 182 |
+
add_suite("CRAN readiness", "failed", "R CMD check --as-cran returned an error.")
|
| 183 |
+
add_finding("high", "RXV-CHECK-001", "00check.log", 0, paste(tail(notes, 1) %||% "R CMD check failed", collapse = ""))
|
| 184 |
+
} else if (length(notes)) {
|
| 185 |
+
add_suite("CRAN readiness", "warning", paste(length(notes), "R CMD check note(s)/warning(s) require review."))
|
| 186 |
+
} else add_suite("CRAN readiness", "passed", "R CMD check --as-cran completed cleanly.")
|
| 187 |
+
})
|
| 188 |
+
|
| 189 |
+
with_suite("Test confidence", function() {
|
| 190 |
+
tests <- file.path(package_dir, "tests", "testthat")
|
| 191 |
+
if (!dir.exists(tests)) { add_suite("Test confidence", "warning", "No tests/testthat directory was found."); return() }
|
| 192 |
+
if (!requireNamespace("testthat", quietly = TRUE)) { add_suite("Test confidence", "skipped", "testthat is unavailable in this runner image."); return() }
|
| 193 |
+
result <- tryCatch({ testthat::test_local(package_dir, reporter = "summary", stop_on_failure = FALSE, stop_on_warning = FALSE); NULL }, error = identity)
|
| 194 |
+
if (inherits(result, "error")) {
|
| 195 |
+
add_suite("Test confidence", "failed", paste("testthat execution failed:", conditionMessage(result)))
|
| 196 |
+
add_finding("high", "RXV-TEST-001", "tests/testthat", 0, conditionMessage(result))
|
| 197 |
+
} else add_suite("Test confidence", "passed", "testthat suite executed in the isolated package environment.")
|
| 198 |
+
})
|
| 199 |
+
|
| 200 |
+
with_suite("Test framework inventory", function() {
|
| 201 |
+
detected <- character(); notes <- character()
|
| 202 |
+
if (dir.exists(file.path(package_dir, "tests", "testthat"))) detected <- c(detected, "testthat")
|
| 203 |
+
if (dir.exists(file.path(package_dir, "inst", "tinytest")) || dir.exists(file.path(package_dir, "tests", "tinytest"))) {
|
| 204 |
+
detected <- c(detected, "tinytest")
|
| 205 |
+
notes <- c(notes, "tinytest tests are executed by R CMD check when declared in the package test hook")
|
| 206 |
+
}
|
| 207 |
+
if (dir.exists(file.path(package_dir, "inst", "unitTests"))) {
|
| 208 |
+
detected <- c(detected, "RUnit")
|
| 209 |
+
notes <- c(notes, "RUnit tests require an explicit test harness; verify this via R CMD check output")
|
| 210 |
+
}
|
| 211 |
+
test_files <- list.files(file.path(package_dir, "tests"), pattern = "\\.[Rr]$", recursive = TRUE, full.names = FALSE)
|
| 212 |
+
if (!length(detected) && !length(test_files)) {
|
| 213 |
+
add_suite("Test framework inventory", "warning", "No automated test framework or test scripts were detected.")
|
| 214 |
+
add_finding("medium", "RXV-TEST-002", "tests/", 0, "Add automated regression tests before releasing a public package.")
|
| 215 |
+
} else add_suite("Test framework inventory", "passed", paste("Detected:", paste(unique(detected), collapse = ", "), "·", length(test_files), "test script(s).", paste(notes, collapse = " ")))
|
| 216 |
+
})
|
| 217 |
+
|
| 218 |
+
if (profile %in% c("standard", "release")) with_suite("Coverage & quality", function() {
|
| 219 |
+
lint_count <- NA_integer_; coverage <- NA_real_
|
| 220 |
+
if (requireNamespace("lintr", quietly = TRUE)) {
|
| 221 |
+
lints <- tryCatch(lintr::lint_package(package_dir), error = identity)
|
| 222 |
+
if (!inherits(lints, "error")) lint_count <- length(lints)
|
| 223 |
+
}
|
| 224 |
+
if (requireNamespace("covr", quietly = TRUE) && dir.exists(file.path(package_dir, "tests"))) {
|
| 225 |
+
cov <- tryCatch(covr::package_coverage(package_dir, quiet = TRUE), error = identity)
|
| 226 |
+
if (!inherits(cov, "error")) coverage <- round(covr::percent_coverage(cov), 1)
|
| 227 |
+
}
|
| 228 |
+
details <- c(if (!is.na(lint_count)) paste(lint_count, "lint finding(s)") else NULL, if (!is.na(coverage)) paste0(coverage, "% coverage") else NULL)
|
| 229 |
+
if (!is.na(lint_count) && lint_count > 0) {
|
| 230 |
+
add_suite("Coverage & quality", "warning", paste(c(details, collapse = " · ")))
|
| 231 |
+
add_finding("low", "RXV-LINT-001", "R/", 0, paste(lint_count, "lintr finding(s) detected."))
|
| 232 |
+
} else add_suite("Coverage & quality", "passed", if (length(details)) paste(details, collapse = " · ") else "Static quality scan completed.")
|
| 233 |
+
})
|
| 234 |
+
|
| 235 |
+
if (profile %in% c("standard", "release")) with_suite("Documentation", function() {
|
| 236 |
+
man <- file.path(package_dir, "man")
|
| 237 |
+
exports <- if (file.exists(file.path(package_dir, "NAMESPACE"))) grep("^(export|S3method)", readLines(file.path(package_dir, "NAMESPACE"), warn = FALSE), value = TRUE) else character()
|
| 238 |
+
rd_files <- if (dir.exists(man)) list.files(man, pattern = "\\.Rd$", full.names = TRUE) else character()
|
| 239 |
+
examples <- if (length(rd_files)) sum(grepl("\\\\examples", unlist(lapply(rd_files, readLines, warn = FALSE)))) else 0
|
| 240 |
+
if (length(exports) && !length(rd_files)) {
|
| 241 |
+
add_suite("Documentation", "warning", "Exported objects were found but no Rd files exist.")
|
| 242 |
+
add_finding("medium", "RXV-DOC-001", "man/", 0, "Document exported functions with roxygen2/Rd topics.")
|
| 243 |
+
} else add_suite("Documentation", "passed", paste(length(rd_files), "Rd topic(s) and", examples, "example section(s) detected."))
|
| 244 |
+
})
|
| 245 |
+
|
| 246 |
+
if (profile %in% c("standard", "release")) with_suite("Examples, vignettes & website assets", function() {
|
| 247 |
+
vignette_dir <- file.path(package_dir, "vignettes")
|
| 248 |
+
vignettes <- if (dir.exists(vignette_dir)) list.files(vignette_dir, pattern = "\\.(Rmd|Rnw|qmd)$", full.names = TRUE, ignore.case = TRUE) else character()
|
| 249 |
+
has_pkgdown <- file.exists(file.path(package_dir, "_pkgdown.yml")) || dir.exists(file.path(package_dir, "docs"))
|
| 250 |
+
broken_rd <- character()
|
| 251 |
+
for (rd in list.files(file.path(package_dir, "man"), pattern = "\\.Rd$", full.names = TRUE)) {
|
| 252 |
+
parsed <- tryCatch(tools::parse_Rd(rd), error = identity)
|
| 253 |
+
if (inherits(parsed, "error")) broken_rd <- c(broken_rd, basename(rd))
|
| 254 |
+
}
|
| 255 |
+
if (length(broken_rd)) {
|
| 256 |
+
add_suite("Examples, vignettes & website assets", "failed", paste("Invalid Rd file(s):", paste(broken_rd, collapse = ", ")))
|
| 257 |
+
add_finding("high", "RXV-DOC-002", "man/", 0, "One or more Rd files cannot be parsed.")
|
| 258 |
+
} else if (!length(vignettes) && !has_pkgdown) {
|
| 259 |
+
add_suite("Examples, vignettes & website assets", "warning", "No vignette or pkgdown website configuration was detected; R CMD check still runs Rd examples.")
|
| 260 |
+
} else add_suite("Examples, vignettes & website assets", paste0("passed"), paste(length(vignettes), "vignette source(s)", if (has_pkgdown) "· pkgdown assets detected" else ""))
|
| 261 |
+
})
|
| 262 |
+
|
| 263 |
+
if (profile == "release") with_suite("Visual & UI regression", function() {
|
| 264 |
+
snapshots <- list.files(package_dir, pattern = "(vdiffr|_snaps|shinytest)", recursive = TRUE, full.names = FALSE)
|
| 265 |
+
has_shiny <- dir.exists(file.path(package_dir, "inst", "shiny")) || any(grepl("shiny::|library\\(shiny", unlist(lapply(r_files, readLines, warn = FALSE))))
|
| 266 |
+
if (!length(snapshots) && !has_shiny) add_suite("Visual & UI regression", "skipped", "No vdiffr snapshots or Shiny application test targets were discovered.")
|
| 267 |
+
else add_suite("Visual & UI regression", "passed", paste("Discovered", length(snapshots), "visual snapshot/UI asset(s); relevant testthat expectations ran in the test suite."))
|
| 268 |
+
})
|
| 269 |
+
|
| 270 |
+
if (profile == "release") with_suite("Cross-platform & release gate", function() {
|
| 271 |
+
platform_calls <- grep("(shell\\(|system\\(|system2\\(|\\.Platform|Sys\\.info)", unlist(lapply(r_files, function(f) tryCatch(readLines(f, warn = FALSE), error = function(e) character()))), value = TRUE)
|
| 272 |
+
min_r <- description[["Depends"]] %||% ""
|
| 273 |
+
matrix_note <- "Single Linux/R runner completed. Multi-version and Windows/macOS checks require the production matrix orchestrator."
|
| 274 |
+
if (length(platform_calls)) {
|
| 275 |
+
add_suite("Cross-platform & release gate", "warning", paste(length(platform_calls), "platform-sensitive call(s) detected.", matrix_note))
|
| 276 |
+
add_finding("medium", "RXV-PORT-001", "R/", 0, "Review OS-specific commands and add CI coverage on supported R versions/platforms.")
|
| 277 |
+
} else add_suite("Cross-platform & release gate", "warning", paste("No obvious OS-specific calls detected.", matrix_note))
|
| 278 |
+
})
|
| 279 |
+
|
| 280 |
+
if (profile %in% c("standard", "release")) with_suite("Reproducibility", function() {
|
| 281 |
+
lock <- file.exists(file.path(package_dir, "renv.lock")); remotes <- description[["Remotes"]] %||% ""
|
| 282 |
+
unpinned <- nzchar(remotes) && !grepl("@([0-9a-f]{7,}|v?[0-9])", remotes)
|
| 283 |
+
if (!lock && !nzchar(remotes)) add_suite("Reproducibility", "warning", "No renv.lock or Remotes declaration was found.")
|
| 284 |
+
else if (unpinned) {
|
| 285 |
+
add_suite("Reproducibility", "warning", "Some remote dependencies may not be pinned to a stable revision.")
|
| 286 |
+
add_finding("medium", "RXV-REPRO-001", "DESCRIPTION", 0, "Pin Remotes dependencies to a tag or commit SHA.")
|
| 287 |
+
} else add_suite("Reproducibility", "passed", if (lock) "renv.lock detected." else "Remote dependency declaration detected.")
|
| 288 |
+
})
|
| 289 |
+
|
| 290 |
+
failed <- sum(vapply(suites, function(x) identical(x$status, "failed"), logical(1)))
|
| 291 |
+
warnings <- sum(vapply(suites, function(x) identical(x$status, "warning"), logical(1)))
|
| 292 |
+
score <- max(0, min(100, 100 - failed * 22 - warnings * 5 - sum(vapply(findings, function(x) x$severity == "high", logical(1))) * 4))
|
| 293 |
+
report <- list(
|
| 294 |
+
schema_version = "1.0", package = pkg_name, profile = profile, score = score,
|
| 295 |
+
verdict = if (failed) "failed" else if (warnings) "passed_with_warnings" else "passed",
|
| 296 |
+
environment = list(r_version = R.version.string, platform = R.version$platform, network = "disabled during execution"),
|
| 297 |
+
suites = suites, findings = findings, command_logs = command_logs,
|
| 298 |
+
artifacts = list()
|
| 299 |
+
)
|
| 300 |
+
dir.create(dirname(report_path), recursive = TRUE, showWarnings = FALSE)
|
| 301 |
+
jsonlite::write_json(report, report_path, auto_unbox = TRUE, pretty = TRUE, null = "null")
|
tests/test_api_contract.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Lightweight contract checks; integration tests run in docker compose."""
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def test_golem_ui_is_the_space_entrypoint():
|
| 6 |
+
dockerfile = Path(__file__).parents[1] / "Dockerfile"
|
| 7 |
+
content = dockerfile.read_text(encoding="utf-8")
|
| 8 |
+
assert "rocker/shiny" in content
|
| 9 |
+
assert "rxv::run_app()" in content
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def test_runner_has_no_public_docs_surface():
|
| 13 |
+
service = (Path(__file__).parents[1] / "runner" / "service.py").read_text(encoding="utf-8")
|
| 14 |
+
assert "docs_url=None" in service
|
| 15 |
+
assert "authorization != f\"Bearer {TOKEN}\"" in service
|