Enroll loomio CI tests and bridge polling
continuous-integration/drone/push Build is failing

This commit is contained in:
notplants
2026-11-26 02:42:13 +00:00
parent 8c04c08f97
commit d35e3265e3
7 changed files with 263 additions and 1 deletions
+38
View File
@@ -0,0 +1,38 @@
# loomio — parity & coverage map
## P2 — Parity port
The recipe-maintainer corpus has **no** `recipe-info/loomio/` directory, so there is no parity
corpus to port. Coverage is delivered by the generic lifecycle tiers (install/upgrade/backup/restore)
plus the recipe-specific tests below.
## Lifecycle (generic tiers)
Loomio ships no `test_<op>.py` overlays, so the generic install/upgrade/backup/restore tiers run.
The stack bundles postgres (`pgautoupgrade`) and redis in-compose, so no external deps are needed.
Backup/restore is asserted by the generic tiers (the `db` service carries backupbot labels and a
`pg_backup.sh` pre/post hook).
## P3 — Recipe-specific functional tests (≥2 non-vacuous)
| cc-ci file | what's verified | why non-vacuous |
|---|---|---|
| `custom/test_api_health.py` | `GET /api/v1/boot/version` → 200 JSON with a release `version`. | Proves the Rails stack booted through DB setup/migrations and the JSON API is live, not just a served page. |
| `custom/test_group_roundtrip.py` | User + **open/public** group created via the Rails console; group read back **anonymously** over `GET /api/v1/groups/<key>`; name + handle round-trip. | Exercises the group write path, the public-visibility ability rule, FriendlyId key lookup and serialization. A broken DB/API layer fails. |
| `custom/test_discussion_roundtrip.py` | User + group + **public discussion** created via `DiscussionService`; discussion read back **anonymously** over `GET /api/v1/discussions/<key>`; title + unique body marker round-trip. | The recipe's defining object; exercises privacy validation, `DiscussionService` event publication and the anonymous visibility query. |
## Why the console (STYLE §1)
Loomio has no unauthenticated write API: account creation is email/login-token based and the REST
API is session-authenticated (Devise + CSRF). The tests therefore create state through the app's own
console (`bundle exec rails runner`) using the same models/services the controllers use — STYLE §1
option 2 — and read it back over public HTTP, a different path. Identifiers are `ccci-`-prefixed with
`.example.com` emails and are run-scoped, so leftover state is attributable and re-runs are safe.
## Deferred
- Session-auth write flow through `POST /api/v1/registrations` + `POST /api/v1/sessions` (needs CSRF
token + cookie jar); the console path already covers the write services, so this would only add
controller-level coverage.
- The separate `channels` service (`loomio_channel_server`, served at `channels.<domain>`) is not
exercised because the harness gates the single app domain.
+109
View File
@@ -0,0 +1,109 @@
"""Shared loomio test helpers.
Loomio is a Rails app. There is no unauthenticated write API (account creation is email/login-token
based and the REST API is session-authenticated), so state is created through the app's own console
(`bundle exec rails runner`) using the same models/services the API controllers use — STYLE §1 option
2. Each test then reads its object back through the PUBLIC HTTP API, a different path, so a broken
DB/serializer/routing layer is named rather than hidden.
Every helper is idempotent: it looks the user/group/discussion up by a run-scoped identifier first.
Identifiers carry the `ccci-` prefix and use `.example.com` (§8) so state left behind on a warm
canonical is attributable.
"""
from __future__ import annotations
import json
import os
import sys
import uuid
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "runner"))
from harness import lifecycle # noqa: E402
RUN_ID = uuid.uuid4().hex[:10]
ADMIN_EMAIL = f"ccci-loomio-{RUN_ID}@ccci.example.com"
ADMIN_PW = "Ccci-Loomio-Test-2026!"
GROUP_NAME = f"ccci loomio {RUN_ID}"
GROUP_HANDLE = f"ccci-loomio-{RUN_ID}"
DISCUSSION_TITLE = f"ccci discussion {RUN_ID}"
DISCUSSION_MARKER = f"ccci-marker-{RUN_ID}-roundtrip"
_EMAIL = json.dumps(ADMIN_EMAIL) # JSON string literals are valid Ruby double-quoted strings
_PW = json.dumps(ADMIN_PW)
_GROUP_NAME = json.dumps(GROUP_NAME)
_GROUP_HANDLE = json.dumps(GROUP_HANDLE)
_DISCUSSION_TITLE = json.dumps(DISCUSSION_TITLE)
_DISCUSSION_MARKER = json.dumps(DISCUSSION_MARKER)
# Creates a verified user + an OPEN, public, explore-listed group owned by that user. Prints the
# group key on its own line so the caller can read it back through the public API.
_GROUP_RUNNER = f"""
email = {_EMAIL}
user = User.find_by(email: email)
unless user
user = User.new(name: "ccci loomio", email: email, email_verified: true,
password: {_PW}, password_confirmation: {_PW})
user.save!
end
user.update!(email_verified: true) unless user.email_verified?
group = Group.find_by(handle: {_GROUP_HANDLE})
unless group
group = Group.new(name: {_GROUP_NAME}, handle: {_GROUP_HANDLE},
group_privacy: "open", listed_in_explore: true)
group.save!
group.add_admin!(user)
end
puts "GROUP_KEY=" + group.reload.key.to_s
"""
# Same, plus a public discussion in that group. Prints both keys.
_DISCUSSION_RUNNER = (
_GROUP_RUNNER
+ f"""
discussion = Discussion.find_by(group_id: group.id, title: {_DISCUSSION_TITLE})
unless discussion
discussion = Discussion.new(title: {_DISCUSSION_TITLE}, description: {_DISCUSSION_MARKER},
group: group, private: false)
DiscussionService.create(discussion: discussion, actor: user)
end
puts "DISCUSSION_KEY=" + discussion.reload.key.to_s
"""
)
def _rails(domain: str, code: str) -> str:
"""Run Ruby through the app's Rails console (the same process the API controllers run in)."""
return lifecycle.exec_in_app(
domain, ["bundle", "exec", "rails", "runner", code], service="app", timeout=300
)
def _key(out: str, prefix: str) -> str:
for line in out.splitlines():
if line.startswith(prefix):
return line.split("=", 1)[1].strip()
raise AssertionError(
f"rails runner did not report {prefix} (last 800 chars of output: {out[-800:]!r})"
)
def ensure_group(domain: str) -> str:
"""Create (or reuse) the run's user + public group; return the group key."""
return _key(_rails(domain, _GROUP_RUNNER), "GROUP_KEY=")
def ensure_discussion(domain: str) -> tuple[str, str]:
"""Create (or reuse) the run's user + public group + public discussion; return (group, discussion) keys."""
out = _rails(domain, _DISCUSSION_RUNNER)
return _key(out, "GROUP_KEY="), _key(out, "DISCUSSION_KEY=")
def unwrap(body: object, root: str) -> dict:
"""AMS wraps responses with a root key (`{"groups": {...}}`); accept a bare object too."""
if isinstance(body, dict) and isinstance(body.get(root), dict):
return body[root]
assert isinstance(body, dict), f"expected a JSON object, got {type(body).__name__}: {body!r}"
return body
+25
View File
@@ -0,0 +1,25 @@
"""loomio — health/liveness of the Rails app through its own JSON API.
`GET /api/v1/boot/version` is served by Api::V1::BootController#version (anonymous) and returns the
running release. It proves the Rails stack booted past DB migrations and is answering — not just that
Traefik served a static page. The generic install tier already asserts real HTTPS serving.
"""
from __future__ import annotations
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "runner"))
from harness import http as harness_http # noqa: E402
def test_api_boot_version_serves(live_app):
url = f"https://{live_app}/api/v1/boot/version"
status, body = harness_http.retry_http_get(url, expect_status=200, max_wait=120, interval=5)
assert status == 200, f"GET {url} HTTP {status}"
assert isinstance(body, dict), f"GET {url} did not return a JSON object: {body!r}"
version = body.get("version")
assert isinstance(version, str) and version.strip(), (
f"GET {url} returned no version string: {body!r}"
)
@@ -0,0 +1,38 @@
"""loomio — create a discussion and read its body back through the public API.
Loomio's core object is a discussion. This creates a user + open group + public discussion through the
app's Rails console (`DiscussionService.create`, the same service the API controller calls), then reads
the discussion back ANONYMOUSLY at `GET /api/v1/discussions/<key>`, asserting the title and the unique
body marker survive.
Non-vacuous: it exercises the discussion write path (privacy validation against the group, author
assignment, event publication) and the anonymous visibility rule (`DiscussionQuery.visible_to` includes
public discussions). A read-back of a different path means a stale/echoed setup cannot pass.
"""
from __future__ import annotations
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "runner"))
import _loomio # noqa: E402
from harness import http as harness_http # noqa: E402
def test_public_discussion_roundtrip(live_app):
_group_key, discussion_key = _loomio.ensure_discussion(live_app)
url = f"https://{live_app}/api/v1/discussions/{discussion_key}"
status, body = harness_http.retry_http_get(url, expect_status=200, max_wait=60, interval=3)
assert status == 200, f"anonymous GET {url} HTTP {status} (public discussion not readable)"
discussion = _loomio.unwrap(body, "discussions")
assert discussion.get("title") == _loomio.DISCUSSION_TITLE, (
f"discussion title did not round-trip: sent {_loomio.DISCUSSION_TITLE!r}, "
f"got {discussion.get('title')!r}"
)
assert _loomio.DISCUSSION_MARKER in str(discussion.get("description")), (
f"discussion body marker missing: sent {_loomio.DISCUSSION_MARKER!r}, "
f"got {discussion.get('description')!r}"
)
@@ -0,0 +1,35 @@
"""loomio — §4.3 create-an-object + read-it-back for a group.
Creates a verified user and a public/open group through the app's own Rails console (the same
`Group`/`Membership` path the API controller uses — STYLE §1 option 2), then reads the group back
ANONYMOUSLY through the public HTTP API (`GET /api/v1/groups/<key>`), a different path.
Non-vacuous: if DB persistence, the public-group ability rule (`Ability::Group#show` requires
`is_visible_to_public`), FriendlyId key lookup, or group serialization is broken, this fails even
though the landing page and health endpoint still answer. The group name/handle are run-scoped.
"""
from __future__ import annotations
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "runner"))
import _loomio # noqa: E402
from harness import http as harness_http # noqa: E402
def test_public_group_roundtrip(live_app):
group_key = _loomio.ensure_group(live_app)
url = f"https://{live_app}/api/v1/groups/{group_key}"
status, body = harness_http.retry_http_get(url, expect_status=200, max_wait=60, interval=3)
assert status == 200, f"anonymous GET {url} HTTP {status} (public group not readable)"
group = _loomio.unwrap(body, "groups")
assert group.get("handle") == _loomio.GROUP_HANDLE, (
f"group handle did not round-trip: sent {_loomio.GROUP_HANDLE!r}, got {group.get('handle')!r}"
)
assert group.get("name") == _loomio.GROUP_NAME, (
f"group name did not round-trip: sent {_loomio.GROUP_NAME!r}, got {group.get('name')!r}"
)
+17
View File
@@ -0,0 +1,17 @@
# Per-recipe harness config for loomio (collaborative decision-making; Rails app + sidekiq
# worker + postgres (pgautoupgrade) + redis, with a separate loomio_channel_server).
#
# `/` redirects into the SPA/dashboard (302 for an anonymous visitor, 200 once it settles), so the
# serving gate accepts both. The real liveness signal is the Rails JSON API under /api/v1.
#
# Boot is heavy: every app start runs `apt install postgresql-client`, `bundle install`, then
# `db:setup`/`db:migrate` before puma. The recipe's healthcheck start_period is only 2m, so give
# the deploy a generous ceiling (DB init + first-boot schema load + asset boot).
HEALTH_PATH = "/"
HEALTH_OK = (200, 302)
DEPLOY_TIMEOUT = 1800
HTTP_TIMEOUT = 900
# canon §2.B: enroll as a DATA-WARM canonical (all recipes enrolled — operator 2026-06-17).
# The weekly sweep promotes this recipe's canonical to its latest green RELEASE TAG.
WARM_CANONICAL = True