Compare commits
29
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a726df5b7c | ||
|
|
9d15d86613 | ||
|
|
6193409838 | ||
|
|
36aa23c4b3 | ||
|
|
db8422afda | ||
|
|
c5c6ec1453 | ||
|
|
158d21ca04 | ||
|
|
86e548f2fc | ||
|
|
3293472cad | ||
|
|
864100b813 | ||
|
|
9971a63635 | ||
|
|
9c29bfcd86 | ||
|
|
8588b058c5 | ||
|
|
d7e19bd9da | ||
|
|
a00fad5553 | ||
|
|
a3ef408de6 | ||
|
|
aa3436fd1d | ||
|
|
4dd33c90e1 | ||
|
|
2e8cf269fb | ||
|
|
92f875621d | ||
|
|
47178a64ce | ||
|
|
d1e27c0e47 | ||
|
|
b29d63d413 | ||
|
|
c5ace6b63f | ||
|
|
ede39ec892 | ||
|
|
e843d7f292 | ||
|
|
aba4773cba | ||
|
|
4f51bff3d0 | ||
|
|
5c4eadaf97 |
@@ -1,19 +0,0 @@
|
|||||||
**/bin
|
|
||||||
**/obj
|
|
||||||
**/node_modules
|
|
||||||
**/dist
|
|
||||||
.git
|
|
||||||
.env
|
|
||||||
.env.*
|
|
||||||
**/keys
|
|
||||||
tests
|
|
||||||
*.tar*
|
|
||||||
**/pms.local.json
|
|
||||||
|
|
||||||
**/payments.local.json
|
|
||||||
.guestops-maintenance.lock
|
|
||||||
.guestops-test-keyring
|
|
||||||
**/__pycache__
|
|
||||||
*.tar.gpg
|
|
||||||
guestops-backup-*
|
|
||||||
guestops-restore-*
|
|
||||||
+16
-22
@@ -1,22 +1,16 @@
|
|||||||
# Generate separate 32-byte hex values with: openssl rand -hex 32
|
# Native .NET configuration. Keep real credentials out of source control.
|
||||||
# Keep .env private (chmod 600). Never commit real values.
|
Mongo__ConnectionString=mongodb://127.0.0.1:27017
|
||||||
MONGO_ROOT_PASSWORD=
|
Mongo__Database=guestops
|
||||||
MONGO_APP_PASSWORD=
|
Keys__Path=./keys
|
||||||
GOOGLE_CLIENT_ID=
|
PublicUrl=https://sandbox-guestops.futuresens.co.uk
|
||||||
GOOGLE_CLIENT_SECRET=
|
AllowedHosts=sandbox-guestops.futuresens.co.uk;localhost;127.0.0.1
|
||||||
GOOGLE_ENABLE_SENDING=false
|
Proxy__KnownAddress=127.0.0.1
|
||||||
# Only API service needs the AI key. AI remains off per hotel until owner opts in.
|
Google__ClientId=
|
||||||
AI_API_KEY=
|
Google__ClientSecret=
|
||||||
AI_MODEL=
|
Google__EnableSending=false
|
||||||
# Optional private host-side JSON file binding internal hotel IDs to OHIP credentials.
|
Ai__ApiKey=
|
||||||
# Default example has no connections. Never commit the real configuration.
|
Ai__Model=
|
||||||
PMS_CONFIG_FILE_HOST=./deploy/pms.example.json
|
AutoReply__EnableLive=false
|
||||||
# CI produces image archives. Set these to the loaded, reviewed commit tags.
|
# Optional private files. Leave unset to disable PMS and payment integrations.
|
||||||
GUESTOPS_API_IMAGE=guestops-api:local
|
Pms__ConfigFile=
|
||||||
GUESTOPS_WORKER_IMAGE=guestops-worker:local
|
Payments__ConfigFile=
|
||||||
|
|
||||||
# Private NMI configuration; leave the empty example until sandbox setup.
|
|
||||||
PAYMENTS_CONFIG_FILE_HOST=./deploy/payments.example.json
|
|
||||||
|
|
||||||
# Enable only after Google delivery and FAQ test-mode acceptance.
|
|
||||||
AUTO_REPLY_ENABLE_LIVE=false
|
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
name: Build and verify web migration
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main, 'codex/**']
|
|
||||||
pull_request:
|
|
||||||
workflow_dispatch:
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
jobs:
|
|
||||||
verify:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
services:
|
|
||||||
mongo:
|
|
||||||
image: mongo:8.0
|
|
||||||
ports: ['27017:27017']
|
|
||||||
options: >-
|
|
||||||
--health-cmd "mongosh --quiet --eval 'db.adminCommand({ping:1}).ok'"
|
|
||||||
--health-interval 10s --health-timeout 5s --health-retries 10
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-dotnet@v4
|
|
||||||
with: { dotnet-version: '10.0.x' }
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with: { node-version: '22', cache: npm, cache-dependency-path: web/package-lock.json }
|
|
||||||
- name: Build services
|
|
||||||
run: dotnet build src/GuestOps.Worker/GuestOps.Worker.csproj -c Release
|
|
||||||
- name: Verify backup validation and failure recovery
|
|
||||||
run: python3 -m unittest discover -s tests -p test_ops.py
|
|
||||||
- name: Build interface
|
|
||||||
working-directory: web
|
|
||||||
run: npm ci && npm run build
|
|
||||||
- name: Start isolated preview API
|
|
||||||
run: |
|
|
||||||
ASPNETCORE_ENVIRONMENT=Development Preview=true dotnet src/GuestOps.Api/bin/Release/net10.0/GuestOps.Api.dll --urls http://127.0.0.1:5180 > /tmp/guestops-api.log 2>&1 &
|
|
||||||
for i in $(seq 1 30); do curl -fsS http://127.0.0.1:5180/health && exit 0; sleep 1; done
|
|
||||||
cat /tmp/guestops-api.log
|
|
||||||
exit 1
|
|
||||||
- name: Verify MongoDB and HTTP boundaries
|
|
||||||
env:
|
|
||||||
MONGO_TEST_URI: mongodb://127.0.0.1:27017
|
|
||||||
TEST_API_URL: http://127.0.0.1:5180
|
|
||||||
run: dotnet run --project tests/GuestOps.Tests/GuestOps.Tests.csproj -c Release
|
|
||||||
- name: Build Linux images
|
|
||||||
run: |
|
|
||||||
docker build --target api -t guestops-api:${{ github.sha }} .
|
|
||||||
docker build --target worker -t guestops-worker:${{ github.sha }} .
|
|
||||||
- name: Package reviewed images
|
|
||||||
if: github.event_name != 'pull_request'
|
|
||||||
run: docker save guestops-api:${{ github.sha }} guestops-worker:${{ github.sha }} | gzip > guestops-images.tar.gz
|
|
||||||
- name: Smoke test production containers and restart persistence
|
|
||||||
env:
|
|
||||||
GUESTOPS_API_IMAGE: guestops-api:${{ github.sha }}
|
|
||||||
GUESTOPS_WORKER_IMAGE: guestops-worker:${{ github.sha }}
|
|
||||||
BOOTSTRAP_EMAIL: ci-owner@example.invalid
|
|
||||||
BOOTSTRAP_HOTEL: CI test hotel
|
|
||||||
run: |
|
|
||||||
export MONGO_ROOT_PASSWORD=$(openssl rand -hex 32)
|
|
||||||
export MONGO_APP_PASSWORD=$(openssl rand -hex 32)
|
|
||||||
export BOOTSTRAP_PASSWORD=$(openssl rand -hex 24)
|
|
||||||
trap 'docker compose down --volumes' EXIT
|
|
||||||
docker compose config --quiet
|
|
||||||
docker compose up -d --no-build
|
|
||||||
curl --retry 30 --retry-delay 2 --retry-all-errors --fail http://127.0.0.1:8080/health
|
|
||||||
docker compose run --rm --no-deps -e BOOTSTRAP_EMAIL -e BOOTSTRAP_HOTEL -e BOOTSTRAP_PASSWORD api --bootstrap
|
|
||||||
python3 tests/production_smoke.py
|
|
||||||
docker compose restart api worker
|
|
||||||
curl --retry 30 --retry-delay 2 --retry-all-errors --fail http://127.0.0.1:8080/health
|
|
||||||
python3 tests/production_smoke.py --read
|
|
||||||
install -m 600 /dev/null .env
|
|
||||||
python3 deploy/ops.py preflight --offline
|
|
||||||
mkdir -m 700 .guestops-test-keyring
|
|
||||||
export GNUPGHOME="$PWD/.guestops-test-keyring"
|
|
||||||
gpg --batch --pinentry-mode loopback --passphrase '' --quick-generate-key 'GuestOps CI <ci@example.invalid>' rsa2048 encr 1d
|
|
||||||
BACKUP_RECIPIENT=$(gpg --batch --with-colons --list-keys | awk -F: '$1=="fpr" {print $10; exit}')
|
|
||||||
backup_dir=$(mktemp -d)
|
|
||||||
python3 deploy/ops.py backup --recipient "$BACKUP_RECIPIENT" --output "$backup_dir/fixture.tar.gpg" --confirm-maintenance
|
|
||||||
python3 deploy/ops.py restore-drill "$backup_dir/fixture.tar.gpg" --api-image "$GUESTOPS_API_IMAGE"
|
|
||||||
curl --retry 30 --retry-delay 2 --retry-all-errors --fail http://127.0.0.1:8080/health/ready
|
|
||||||
python3 tests/production_smoke.py --read
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
if: github.event_name != 'pull_request'
|
|
||||||
with:
|
|
||||||
name: guestops-linux-${{ github.run_number }}
|
|
||||||
path: guestops-images.tar.gz
|
|
||||||
retention-days: 7
|
|
||||||
@@ -17,7 +17,10 @@
|
|||||||
**/payments.local.json
|
**/payments.local.json
|
||||||
.guestops-maintenance.lock
|
.guestops-maintenance.lock
|
||||||
.guestops-test-keyring/
|
.guestops-test-keyring/
|
||||||
|
.guestops-release/
|
||||||
guestops-backup-*/
|
guestops-backup-*/
|
||||||
guestops-restore-*/
|
guestops-restore-*/
|
||||||
*.tar.gpg
|
*.tar.gpg
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|
||||||
|
.fake
|
||||||
|
|||||||
Vendored
+36
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "GuestOps API (Preview)",
|
||||||
|
"type": "coreclr",
|
||||||
|
"request": "launch",
|
||||||
|
"preLaunchTask": "build-api",
|
||||||
|
"program": "${workspaceFolder}/src/GuestOps.Api/bin/Debug/net10.0/GuestOps.Api.dll",
|
||||||
|
"cwd": "${workspaceFolder}/src/GuestOps.Api",
|
||||||
|
"env": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
|
"Preview": "true",
|
||||||
|
"ASPNETCORE_URLS": "http://127.0.0.1:5180"
|
||||||
|
},
|
||||||
|
"stopAtEntry": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "GuestOps Web (Vite)",
|
||||||
|
"type": "node-terminal",
|
||||||
|
"request": "launch",
|
||||||
|
"command": "npm run dev",
|
||||||
|
"cwd": "${workspaceFolder}/web"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"compounds": [
|
||||||
|
{
|
||||||
|
"name": "GuestOps: API + Web",
|
||||||
|
"configurations": [
|
||||||
|
"GuestOps API (Preview)",
|
||||||
|
"GuestOps Web (Vite)"
|
||||||
|
],
|
||||||
|
"stopAll": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Vendored
+15
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "build-api",
|
||||||
|
"type": "process",
|
||||||
|
"command": "dotnet",
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"${workspaceFolder}/src/GuestOps.Api/GuestOps.Api.csproj"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1 +1,9 @@
|
|||||||
<Project><PropertyGroup><TargetFramework>net10.0</TargetFramework><Nullable>enable</Nullable><ImplicitUsings>enable</ImplicitUsings><TreatWarningsAsErrors>true</TreatWarningsAsErrors></PropertyGroup></Project>
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<Version>0.2.2</Version>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
|
|||||||
-31
@@ -1,31 +0,0 @@
|
|||||||
FROM node:22-bookworm-slim AS frontend
|
|
||||||
WORKDIR /build/web
|
|
||||||
COPY web/package*.json ./
|
|
||||||
RUN npm ci --no-audit --no-fund
|
|
||||||
COPY web/ ./
|
|
||||||
RUN npm run build
|
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS backend
|
|
||||||
WORKDIR /build
|
|
||||||
COPY Directory.Build.props ./
|
|
||||||
COPY src/ ./src/
|
|
||||||
RUN dotnet publish src/GuestOps.Api/GuestOps.Api.csproj -c Release -o /publish/api
|
|
||||||
RUN dotnet publish src/GuestOps.Worker/GuestOps.Worker.csproj -c Release -o /publish/worker
|
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS api
|
|
||||||
WORKDIR /app
|
|
||||||
RUN mkdir -p /var/lib/guestops/keys && chown -R app:app /var/lib/guestops && chmod 700 /var/lib/guestops/keys
|
|
||||||
COPY --from=backend /publish/api ./
|
|
||||||
COPY --from=frontend /build/web/dist ./wwwroot/
|
|
||||||
ENV ASPNETCORE_URLS=http://+:8080 ASPNETCORE_ENVIRONMENT=Production Keys__Path=/var/lib/guestops/keys
|
|
||||||
USER app
|
|
||||||
EXPOSE 8080
|
|
||||||
ENTRYPOINT ["dotnet", "GuestOps.Api.dll"]
|
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS worker
|
|
||||||
WORKDIR /app
|
|
||||||
RUN mkdir -p /var/lib/guestops/keys && chown -R app:app /var/lib/guestops && chmod 700 /var/lib/guestops/keys
|
|
||||||
COPY --from=backend /publish/worker ./
|
|
||||||
ENV DOTNET_ENVIRONMENT=Production Keys__Path=/var/lib/guestops/keys
|
|
||||||
USER app
|
|
||||||
ENTRYPOINT ["dotnet", "GuestOps.Worker.dll"]
|
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
# GuestOps Milestone Report
|
||||||
|
|
||||||
|
Version: **0.2.2 release candidate**
|
||||||
|
Last updated: **22 October 2026**
|
||||||
|
|
||||||
|
This is the working delivery tracker for GuestOps Web. Update a milestone when its state changes and link the pull request, release artifact, test run, or acceptance record that proves the change.
|
||||||
|
|
||||||
|
## Milestones at a glance
|
||||||
|
|
||||||
|
This summary explains what each milestone delivers and where it currently stands. The release-gate and delivery tables below contain the detailed evidence and exit conditions.
|
||||||
|
|
||||||
|
| # | Milestone | What it delivers | Current position |
|
||||||
|
| ---: | --- | --- | --- |
|
||||||
|
| 1 | Web foundation | The React application, ASP.NET Core API, tenant-isolated MongoDB storage, preview mode, and native Linux foundation. | **Implemented.** The application foundation and automated tests are on `main`. |
|
||||||
|
| 2 | AI suggestions and reviewed Gmail sending | AI-assisted reply drafts and staff-reviewed Gmail delivery with safety and duplicate-send controls. | **Implemented; acceptance required.** Real Gmail threading, revocation, uncertain-send, and staff-review scenarios still need live evidence. |
|
||||||
|
| 3 | OHIP PMS workflow | Internal proposal, approval, and execution controls for PMS operations. | **Implemented; acceptance required.** The workflow exists, but provider-contract and sandbox acceptance remain outstanding. |
|
||||||
|
| 4 | NMI payment workflow | Internal payment proposal, approval, status, expiry, and reconciliation controls. | **Implemented; acceptance required.** The workflow exists, but real payment-provider sandbox acceptance remains outstanding. |
|
||||||
|
| 5 | FAQ automation | Knowledge-based FAQ drafting, test mode, approval controls, and guarded live automation. | **Implemented; acceptance required.** Live mode remains disabled pending quality, false-positive, monitoring, and rollback acceptance. |
|
||||||
|
| 6 | Team onboarding and account recovery | Staff invitations, password setup/reset, access disable/restore, and administrator recovery. | **Implemented; acceptance required.** Deployed link delivery, expiry, recovery, and administrator procedures still need operational evidence. |
|
||||||
|
| 7 | Google connection recovery | OAuth reconnect, checkpoint recovery, grant revocation handling, and worker restart safety. | **Implemented; acceptance required.** Dedicated Google-account and worker-restart exercises have not yet been accepted. |
|
||||||
|
| 8 | Operational readiness | Host backup, monitoring, and recovery are provided by the existing central infrastructure. | **External.** GuestOps no longer carries a second application-specific operational stack. |
|
||||||
|
| 9 | Versioned releases | A deterministic version-named native archive and Ansible-controlled installation. | **Implemented; acceptance required.** Package the tested commit as `guestops_<version>.tar.gz` and deploy it through the central playbook. |
|
||||||
|
| 10 | Debian deployment and persistence | Native systemd deployment, HTTPS, local MongoDB, and persistent Data Protection keys. | **In progress.** The single Ansible playbook installs the self-contained API/worker, configures Nginx, restricts the listener and checks public readiness; sandbox deployment remains to be exercised. |
|
||||||
|
| 11 | Backups, monitoring, and recovery | Existing central MongoDB backup, Filebeat, host monitoring, and version-based rollback. | **External.** Rollback selects an older archive and reruns the same deployment playbook. |
|
||||||
|
| 12 | Google mailbox acceptance | End-to-end Gmail consent, import, recovery, reviewed sending, reconciliation, and revocation evidence. | **In progress.** The runbook, record validator and release-bound Gate B bundle integration exist; the live synthetic-data exercise and independent review remain outstanding. |
|
||||||
|
| 13 | Rezlynx/Guestline adapter | The real PMS provider adapter, mappings, idempotency, reconciliation, and ambiguous-write handling. | **Planned.** Provider contract and sandbox access are still required before implementation and acceptance. |
|
||||||
|
| 14 | Payment links and status | The real payment-provider integration, webhooks, expiry, replay protection, and reconciliation. | **Planned.** The provider path and sandbox acceptance plan still need to be confirmed and completed. |
|
||||||
|
| 15 | Knowledge, AI, and FAQ activation | Supervised knowledge-quality, AI-draft, FAQ test-mode, staff-training, and stop-control acceptance. | **Implemented; acceptance required.** Evaluation tooling and cross-release bundle validation exist; the supervised evaluation, staff training and independent approval remain outstanding. |
|
||||||
|
| 16 | Identity, preferences, and privacy | Account/session controls, hotel preferences, privacy inventory, retention decisions, and audit review. | **Implemented; acceptance required.** Legal and operational decisions, identity checks, and independent review remain outstanding. |
|
||||||
|
| 17 | Inbox usability and desktop parity | Stable pagination, protected unsaved drafts, hotel-timezone display, and desktop workflow parity. | **Implemented; acceptance required.** Automated checks pass; the supervised desktop exercise and independent approval remain outstanding. |
|
||||||
|
| 18 | Pilot, capacity, and release approval | Capacity proof, incident exercise, five-business-day hotel pilot, findings closure, and Gate B approval. | **In progress.** Live prerequisites, incident rehearsal, five-day pilot and named approvals remain open. |
|
||||||
|
| 19 | Account security and self-service | TOTP MFA, recovery codes, transactional email, granular roles, preferences, and security notifications. | **Implemented on the development branch; acceptance required.** Keep it separate until `0.2.2` is approved and tagged, then review, merge, and version it as `0.3.0`. |
|
||||||
|
|
||||||
|
## Status key
|
||||||
|
|
||||||
|
- **Implemented** — present on `main` and supported by code or automated-test evidence.
|
||||||
|
- **In progress** — repository or environment work has started but an exit condition remains open.
|
||||||
|
- **Acceptance required** — implemented in code but still requires a real provider, Debian host, or operational exercise.
|
||||||
|
- **Planned** — work is not yet complete.
|
||||||
|
- **Deferred** — intentionally outside the current release gate.
|
||||||
|
|
||||||
|
## Release gates
|
||||||
|
|
||||||
|
| Gate | Outcome | Current assessment | Exit condition |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| A | Website operational | Not yet approved | Reproducible release on the target Debian host, persistent data/keys, HTTPS, monitoring, and a successful backup/restore drill. |
|
||||||
|
| B | Supervised hotel pilot | Not yet approved | Gate A plus real Google acceptance, staff workflow acceptance, controlled AI/FAQ activation, and closure or explicit containment of pilot usability and security findings. |
|
||||||
|
| C | Integrated rollout | Not yet approved | Gate B plus independently accepted PMS and payment integrations, identity/privacy controls, capacity evidence, and formal release approval. |
|
||||||
|
|
||||||
|
## Delivery milestones
|
||||||
|
|
||||||
|
| # | Milestone | Gate | Status | Evidence and remaining work |
|
||||||
|
| ---: | --- | :---: | --- | --- |
|
||||||
|
| 1 | Web foundation | A | Implemented | The current `main` branch provides the React workspace, ASP.NET Core API, tenant-scoped MongoDB access, read-only Google import foundation, preview mode, native Linux packaging, and automated tests. Live provider and host acceptance still apply. |
|
||||||
|
| 2 | AI suggestions and reviewed Gmail sending | B | Implemented / acceptance required | Promoted to local `main`; verify real mailbox threading, reconnect/revocation, duplicate-send prevention, uncertain outcomes, and staff review before pilot use. |
|
||||||
|
| 3 | OHIP PMS workflow | C | Implemented / acceptance required | Proposal, approval, and execution controls are promoted to local `main`. Provider sandbox and contract-level acceptance remain independent requirements. |
|
||||||
|
| 4 | NMI payment workflow | C | Implemented / acceptance required | Payment proposal and approval controls are promoted to local `main`. Sandbox acceptance, reconciliation, expiry, and ambiguous-result recovery remain required. |
|
||||||
|
| 5 | FAQ automation | B | Implemented / acceptance required | Draft and approval controls are promoted to local `main`. Keep live automation disabled until knowledge quality, thresholds, and rollback behaviour pass acceptance. |
|
||||||
|
| 6 | Team onboarding and account recovery | B | Implemented / acceptance required | Invitation, password reset, and recovery flows are promoted to local `main`; verify deployed links, mail delivery, token expiry, and administrator recovery procedures. |
|
||||||
|
| 7 | Google connection recovery | B | Implemented / acceptance required | Connection epochs, checkpoint recovery, and revocation handling are promoted to local `main`; complete real Google acceptance and worker-restart exercises. |
|
||||||
|
| 8 | Operational readiness tooling | A | External | Use the existing host backup, Filebeat, monitoring and recovery processes instead of a second GuestOps-specific operational stack. |
|
||||||
|
| 9 | Gitea and versioned releases | A | In progress | `deploy/package_release.py` builds an explicit committed ref as an immutable self-contained Linux x64 `guestops_<version>.tar.gz`, verifies matching .NET/frontend versions, and refuses overwrite. Deploy it through the central version-selected Ansible playbook. |
|
||||||
|
| 10 | Debian deployment and persistence | A | In progress | Native systemd services run the API and worker against local MongoDB, preserve `/var/lib/guestops/keys`, and bind the API to loopback. Exercise the single Ansible playbook on sandbox and confirm a second deployment preserves the keys. |
|
||||||
|
| 11 | Backups, monitoring, and recovery | A | External | The existing central MongoDB backup, Filebeat, host monitoring and archive retention remain authoritative. Rollback selects an earlier GuestOps version and reruns the deployment playbook. |
|
||||||
|
| 12 | Google mailbox and reviewed-reply acceptance | B | In progress | The synthetic-data provider runbook, exact scenario set and restricted-record validator are implemented and wired into the Gate B bundle validator. Complete every scenario against the accepted Debian release and dedicated Google sandbox accounts, independently review the evidence, and retain the validated record. |
|
||||||
|
| 13 | Rezlynx/Guestline adapter | C | Planned | Obtain the provider contract and sandbox, implement the adapter and mapping, and accept idempotency, stale-data, ambiguous-write, and reconciliation paths. |
|
||||||
|
| 14 | Payment links and status | C | Planned | Select/confirm the payment-provider path, complete sandbox and webhook acceptance, and prove expiry, replay protection, reconciliation, and support recovery. |
|
||||||
|
| 15 | Knowledge, AI, and FAQ activation | B | Implemented / acceptance required | Owners can run a bounded no-send batch evaluation, and a release-bound acceptance record enforces positive/negative coverage, zero FAQ errors, separate AI review, staff training, stop-control evidence and named monitoring/rollback owners. The integrated Gate B bundle rejects release or environment mismatches. Complete the supervised evaluation and retain independent approval. |
|
||||||
|
| 16 | Identity, preferences, and privacy | B/C | Implemented / acceptance required | Login throttling trusts the client address only after one-hop processing by the configured proxy. A release-bound review now covers owner-controlled preferences, account/session controls, data inventory, retention/deletion/legal-hold ownership, provider decisions, audit evidence and known identity limitations. Complete the legal/operational decisions and independently approve the record. |
|
||||||
|
| 17 | Inbox usability and desktop parity | B | Implemented / acceptance required | The inbox uses tenant-scoped stable cursor pagination in pages of 50 and protects unsaved drafts during route/history navigation, reload, conversation selection, filtering and search. Operational timestamps use the saved hotel timezone, and a release-bound desktop-parity acceptance record is implemented. The implementation and preview HTTP suite pass; run the supervised exercise against the approved release and retain independent approval. |
|
||||||
|
| 18 | Pilot, capacity, and release approval | B/C | In progress | Complete the live Gate A/B exercises against the selected version, resolve or contain findings, and retain separate hotel-owner and technical approval. Gate C remains dependent on milestones 13 and 14. |
|
||||||
|
|
||||||
|
## Delivery sequence
|
||||||
|
|
||||||
|
The current critical path is:
|
||||||
|
|
||||||
|
`9 → 10 → 11 → 12 → 15 → 18`
|
||||||
|
|
||||||
|
Milestones 13 (Guestline/Rezlynx) and 14 (payments) can progress as parallel provider tracks. They do not need to delay a Google-only supervised pilot, but both remain independently gated before Gate C.
|
||||||
|
|
||||||
|
## Next actions
|
||||||
|
|
||||||
|
- [ ] Merge the Action removal and release-process update to the intended default branch; that resulting commit becomes the new package candidate.
|
||||||
|
- [x] Preserve the published `0.2.0` tag unchanged and use the clean `0.2.2` candidate line from `main`, excluding Milestone 19 application code.
|
||||||
|
- [ ] Create the immutable versioned archive with `deploy/package_release.py`, copy it into the Ansible files directory, and select its version in group vars.
|
||||||
|
- [ ] Create and archive the immutable `0.2.2` approval tag only after Gate B approval.
|
||||||
|
- [ ] Deploy to the target Debian environment with persistent MongoDB and data-protection keys.
|
||||||
|
- [ ] Confirm the existing central backup and monitoring processes include GuestOps, then test rollback by selecting the previous version.
|
||||||
|
- [ ] Complete real Google mailbox acceptance without using production guest data.
|
||||||
|
- [ ] Resolve or explicitly contain the milestone 16–17 pilot findings listed above.
|
||||||
|
- [ ] Obtain the Guestline/Rezlynx interface contract and sandbox access.
|
||||||
|
- [ ] Agree the payment-provider acceptance and reconciliation plan.
|
||||||
|
- [ ] Capture named owners and target dates for milestones 9–18.
|
||||||
|
|
||||||
|
## Tracking convention
|
||||||
|
|
||||||
|
For every status update, add the owner, target or completion date, and evidence link to the relevant row or to an issue referenced from that row. A milestone is not complete solely because code exists: provider and host acceptance must be recorded wherever the status says **Acceptance required**.
|
||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
A Linux-hosted hotel email workspace, developed separately from the Windows GuestOps application. **This migration now includes AI draft generation, staff-approved Gmail sending, reviewed OHIP reservation updates, NMI hosted invoices, controlled FAQ auto-replies and team onboarding. It is not yet a production-complete replacement.**
|
A Linux-hosted hotel email workspace, developed separately from the Windows GuestOps application. **This migration now includes AI draft generation, staff-approved Gmail sending, reviewed OHIP reservation updates, NMI hosted invoices, controlled FAQ auto-replies and team onboarding. It is not yet a production-complete replacement.**
|
||||||
|
|
||||||
|
Current release-candidate version: **0.2.2**
|
||||||
|
|
||||||
|
Project progress is tracked in the [milestone report](MILESTONES.md). User-visible changes and release limitations are recorded in the [release notes](RELEASE_NOTES.md).
|
||||||
|
|
||||||
## Implemented so far
|
## Implemented so far
|
||||||
|
|
||||||
- Responsive React inbox, message search and status filters, editable saved drafts, approved hotel answers, activity history and hotel settings.
|
- Responsive React inbox, message search and status filters, editable saved drafts, approved hotel answers, activity history and hotel settings.
|
||||||
@@ -15,7 +19,7 @@ A Linux-hosted hotel email workspace, developed separately from the Windows Gues
|
|||||||
- Controlled FAQ auto-replies: exact plain-text questions, owner-reviewed answers, test mode, daily quotas and thread/knowledge rechecks. Live mode defaults off.
|
- Controlled FAQ auto-replies: exact plain-text questions, owner-reviewed answers, test mode, daily quotas and thread/knowledge rechecks. Live mode defaults off.
|
||||||
- Owner-issued staff invitations, assisted password recovery, session invalidation, disabled-account restoration and a hotel setup checklist. See [team access](docs/accounts.md).
|
- Owner-issued staff invitations, assisted password recovery, session invalidation, disabled-account restoration and a hotel setup checklist. See [team access](docs/accounts.md).
|
||||||
- Google mailbox health, owner-only disconnect/reconnect and import restart, revoked-consent handling, retry delays and connection-bound delivery approvals. See [mailbox management](docs/mailboxes.md).
|
- Google mailbox health, owner-only disconnect/reconnect and import restart, revoked-consent handling, retry delays and connection-bound delivery approvals. See [mailbox management](docs/mailboxes.md).
|
||||||
- Docker image builds, private MongoDB configuration and an Nginx HTTPS example for the Debian sandbox.
|
- Self-contained Linux API and worker releases, native systemd services, local MongoDB configuration and an Nginx HTTPS example for the Debian sandbox.
|
||||||
|
|
||||||
## Explicit limits
|
## Explicit limits
|
||||||
|
|
||||||
@@ -53,7 +57,9 @@ Open http://127.0.0.1:5173 and select **Open preview workspace**. Each preview l
|
|||||||
|
|
||||||
For MongoDB-backed operation, disable Preview and set `Mongo__ConnectionString`, `Mongo__Database`, and a persistent private `Keys__Path`. See [deployment](docs/deployment.md).
|
For MongoDB-backed operation, disable Preview and set `Mongo__ConnectionString`, `Mongo__Database`, and a persistent private `Keys__Path`. See [deployment](docs/deployment.md).
|
||||||
|
|
||||||
Operational tooling includes an owner-only Workspace health page and Linux deployment preflight, encrypted backup and isolated restore drill. See [operations and recovery](docs/operations.md) before the hotel pilot.
|
The owner-only Workspace health page remains available in the application. Host monitoring, MongoDB backup and disaster recovery are provided by the existing central infrastructure.
|
||||||
|
|
||||||
|
Release packaging is runner-free. `deploy/package_release.py` builds an immutable, self-contained Linux x64 `guestops_<version>.tar.gz` archive from one explicit committed Git ref for handoff to the Futuresens Ansible deployment. It never packages uncommitted working-tree files. Target servers need no application build tooling or .NET runtime installation.
|
||||||
|
|
||||||
## Verification
|
## Verification
|
||||||
|
|
||||||
@@ -62,7 +68,7 @@ dotnet run --project tests/GuestOps.Tests
|
|||||||
cd web && npm ci && npm run build
|
cd web && npm ci && npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
Set `MONGO_TEST_URI` to an isolated MongoDB server and `TEST_API_URL=http://127.0.0.1:5180` with a preview API running to enable database and HTTP integration checks. The suite creates and drops only its own randomly named `guestops_test_*` database. CI runs both integrations and builds both Linux images.
|
Set `MONGO_TEST_URI` to an isolated MongoDB server and `TEST_API_URL=http://127.0.0.1:5180` with a preview API running to enable database and HTTP integration checks. The suite creates and drops only its own randomly named `guestops_test_*` database. Run these checks before creating a versioned release package. GuestOps does not require a Gitea Actions runner; deployment follows the existing Futuresens release-package and Ansible process described in the [deployment guide](docs/deployment.md).
|
||||||
|
|
||||||
See [controlled FAQ automation](docs/auto-replies.md), [NMI payment setup and recovery](docs/payments.md), [OHIP reservation setup and recovery](docs/pms.md), [AI drafts and reply delivery setup](docs/replies.md), [migration status](docs/migration.md) and [deployment guide](docs/deployment.md).
|
See [controlled FAQ automation](docs/auto-replies.md), [NMI payment setup and recovery](docs/payments.md), [OHIP reservation setup and recovery](docs/pms.md), [AI drafts and reply delivery setup](docs/replies.md), [migration status](docs/migration.md) and [deployment guide](docs/deployment.md).
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
# GuestOps Release Notes
|
||||||
|
|
||||||
|
## 0.2.2 — Gate B native deployment candidate
|
||||||
|
|
||||||
|
This candidate freezes the implemented Gate B scope for controlled acceptance and replaces the unsuccessful source-build `0.2.1` deployment artifact with self-contained Linux x64 API and worker applications managed by systemd. It is not yet approved for live hotel operations and does not become a release until the exact commit is pushed, a checksummed native package and operational evidence are retained, the supervised pilot is approved and the immutable `0.2.2` tag is created.
|
||||||
|
|
||||||
|
### Promoted scope
|
||||||
|
|
||||||
|
- AI-assisted reply suggestions and staff-reviewed Gmail sending.
|
||||||
|
- Approval-controlled OHIP PMS and NMI payment workflows.
|
||||||
|
- FAQ automation controls, team invitations, password recovery, and stronger Google connection recovery.
|
||||||
|
- No-send FAQ batch evaluation with false-positive and false-negative reporting before activation.
|
||||||
|
- Release-bound automation and identity/privacy acceptance records covering training, provider decisions, retention ownership and known limitations.
|
||||||
|
- Stable tenant-scoped inbox pagination beyond the former 500-message view, unsaved-draft guards including browser history navigation, consistent hotel-timezone timestamps across operational screens, and a release-bound desktop-parity acceptance record.
|
||||||
|
- A bounded read-only sandbox capacity probe plus machine-validated, release-bound supervised-pilot run, go/no-go and incident-exercise records.
|
||||||
|
- Native systemd API and worker deployment with persistent Data Protection keys, loopback-only HTTP, Nginx HTTPS, and version-selected rollback.
|
||||||
|
|
||||||
|
These capabilities still require their separately documented provider, host and operational acceptance. Google, PMS and payment-provider acceptance is not established by local automated tests.
|
||||||
|
|
||||||
|
### Known limitations and launch conditions
|
||||||
|
|
||||||
|
- Gate A still requires a checksummed native package from the exact default-branch commit, Ansible installation on the target Debian host, persistent storage/key validation, monitoring, and a successful restore/rollback exercise.
|
||||||
|
- Gate B still requires real Google acceptance and supervised staff testing, including desktop-parity acceptance of pagination, draft protection, proxy-aware login throttling and saved-hotel-timezone rendering.
|
||||||
|
- Gate C still requires the Rezlynx/Guestline adapter and independently accepted PMS/payment workflows, plus privacy, identity, capacity, and release approvals.
|
||||||
|
- FAQ live mode and all external write actions must remain disabled until their corresponding acceptance gate has passed.
|
||||||
|
|
||||||
|
See [MILESTONES.md](MILESTONES.md) for the gate assessment, delivery sequence, and remaining work.
|
||||||
|
|
||||||
|
## 0.2.0 — Superseded candidate identifier
|
||||||
|
|
||||||
|
The published `0.2.0` tag is retained unchanged for auditability but is not the approved deployment candidate. It identifies a development-line commit that is not on the clean Gate B release branch. Do not package or deploy it; `0.2.2` supersedes it.
|
||||||
|
|
||||||
|
## 0.1.0 — 29 September 2026
|
||||||
|
|
||||||
|
The `0.1.0` tag identifies the initial GuestOps Web foundation. It is not approved for live hotel operations.
|
||||||
|
|
||||||
|
### Foundation scope
|
||||||
|
|
||||||
|
- Responsive shared inbox, search and status filters, saved reply drafts, approved hotel answers, activity history, and hotel settings.
|
||||||
|
- ASP.NET Core authentication with protected cookies, password hashing, CSRF validation, login throttling, role checks, and server-derived hotel membership.
|
||||||
|
- Tenant-scoped MongoDB storage with optimistic concurrency, unique mailbox/message indexes, OAuth state expiry, and worker leases.
|
||||||
|
- Read-only Google OAuth and recent-message import foundation with checkpoint and duplicate protection.
|
||||||
|
- Preview mode, native Linux packaging, Nginx HTTPS example, and automated backend/frontend verification.
|
||||||
|
- Live email sending, PMS writes, payment workflows, and automatic FAQ replies were disabled in this foundation.
|
||||||
|
|
||||||
|
### Versioning
|
||||||
|
|
||||||
|
The foundation remains tagged `0.1.0`. The .NET projects and frontend package now share candidate version `0.2.2`; create that immutable tag only after the exact commit, checksummed artifacts and Gate B acceptance evidence have been approved.
|
||||||
-77
@@ -1,77 +0,0 @@
|
|||||||
name: guestops
|
|
||||||
x-app-env: &app-env
|
|
||||||
Mongo__ConnectionString: mongodb://guestops:${MONGO_APP_PASSWORD:?Set MONGO_APP_PASSWORD}@mongo:27017/guestops?authSource=guestops
|
|
||||||
Mongo__Database: guestops
|
|
||||||
Keys__Path: /var/lib/guestops/keys
|
|
||||||
PublicUrl: https://sandbox-guestops.futuresens.co.uk
|
|
||||||
Google__ClientId: ${GOOGLE_CLIENT_ID:-}
|
|
||||||
Google__ClientSecret: ${GOOGLE_CLIENT_SECRET:-}
|
|
||||||
AutoReply__EnableLive: ${AUTO_REPLY_ENABLE_LIVE:-false}
|
|
||||||
Google__EnableSending: ${GOOGLE_ENABLE_SENDING:-false}
|
|
||||||
Logging__LogLevel__Default: Warning
|
|
||||||
Logging__LogLevel__Microsoft.AspNetCore.Hosting.Diagnostics: Warning
|
|
||||||
x-logging: &logging
|
|
||||||
driver: json-file
|
|
||||||
options: { max-size: "10m", max-file: "3" }
|
|
||||||
services:
|
|
||||||
api:
|
|
||||||
image: ${GUESTOPS_API_IMAGE:-guestops-api:local}
|
|
||||||
build: { context: ., target: api }
|
|
||||||
restart: unless-stopped
|
|
||||||
ports: ["127.0.0.1:8080:8080"]
|
|
||||||
environment:
|
|
||||||
<<: *app-env
|
|
||||||
ASPNETCORE_ENVIRONMENT: Production
|
|
||||||
AllowedHosts: sandbox-guestops.futuresens.co.uk;localhost;127.0.0.1
|
|
||||||
Proxy__KnownAddress: ${GUESTOPS_GATEWAY:-172.30.87.1}
|
|
||||||
Ai__ApiKey: ${AI_API_KEY:-}
|
|
||||||
Ai__Model: ${AI_MODEL:-}
|
|
||||||
Payments__ConfigFile: /run/guestops/payments.json
|
|
||||||
Pms__ConfigFile: /run/guestops/pms.json
|
|
||||||
volumes:
|
|
||||||
- app-keys:/var/lib/guestops/keys
|
|
||||||
- ${PMS_CONFIG_FILE_HOST:-./deploy/pms.example.json}:/run/guestops/pms.json:ro
|
|
||||||
- ${PAYMENTS_CONFIG_FILE_HOST:-./deploy/payments.example.json}:/run/guestops/payments.json:ro
|
|
||||||
depends_on:
|
|
||||||
mongo: { condition: service_healthy }
|
|
||||||
logging: *logging
|
|
||||||
mem_limit: 1g
|
|
||||||
security_opt: ["no-new-privileges:true"]
|
|
||||||
worker:
|
|
||||||
image: ${GUESTOPS_WORKER_IMAGE:-guestops-worker:local}
|
|
||||||
build: { context: ., target: worker }
|
|
||||||
restart: unless-stopped
|
|
||||||
environment: *app-env
|
|
||||||
volumes: ["app-keys:/var/lib/guestops/keys"]
|
|
||||||
depends_on:
|
|
||||||
mongo: { condition: service_healthy }
|
|
||||||
logging: *logging
|
|
||||||
mem_limit: 768m
|
|
||||||
security_opt: ["no-new-privileges:true"]
|
|
||||||
mongo:
|
|
||||||
image: mongo:8.0
|
|
||||||
restart: unless-stopped
|
|
||||||
environment:
|
|
||||||
MONGO_INITDB_ROOT_USERNAME: admin
|
|
||||||
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ROOT_PASSWORD:?Set MONGO_ROOT_PASSWORD}
|
|
||||||
MONGO_APP_PASSWORD: ${MONGO_APP_PASSWORD:?Set MONGO_APP_PASSWORD}
|
|
||||||
volumes:
|
|
||||||
- mongo-data:/data/db
|
|
||||||
- ./deploy/mongo-init.js:/docker-entrypoint-initdb.d/guestops.js:ro
|
|
||||||
command: ["mongod", "--wiredTigerCacheSizeGB", "1"]
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD-SHELL", "mongosh --quiet --eval 'db.adminCommand({ping:1}).ok' | grep 1"]
|
|
||||||
interval: 10s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 12
|
|
||||||
logging: *logging
|
|
||||||
mem_limit: 2500m
|
|
||||||
volumes:
|
|
||||||
mongo-data:
|
|
||||||
app-keys:
|
|
||||||
networks:
|
|
||||||
default:
|
|
||||||
ipam:
|
|
||||||
config:
|
|
||||||
- subnet: ${GUESTOPS_SUBNET:-172.30.87.0/24}
|
|
||||||
gateway: ${GUESTOPS_GATEWAY:-172.30.87.1}
|
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"system": "guestops-automation-acceptance",
|
||||||
|
"targetGate": "B",
|
||||||
|
"dataClassification": "synthetic-only",
|
||||||
|
"releaseCommit": "0000000000000000000000000000000000000000",
|
||||||
|
"releaseRecordSha256": "0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"environment": "https://sandbox-guestops.example.invalid",
|
||||||
|
"operator": "REPLACE OPERATOR",
|
||||||
|
"reviewedBy": "REPLACE REVIEWER",
|
||||||
|
"startedAt": "2026-10-01T09:00:00Z",
|
||||||
|
"endedAt": "2026-10-01T10:00:00Z",
|
||||||
|
"reviewedAt": "2026-10-01T11:00:00Z",
|
||||||
|
"faqEvaluation": {"positiveCases": 0, "negativeCases": 0, "falsePositives": 0, "falseNegatives": 0, "reportSha256": "0000000000000000000000000000000000000000000000000000000000000000"},
|
||||||
|
"aiEvaluation": {"casesReviewed": 0, "unsafeDraftsApproved": 0, "reportSha256": "0000000000000000000000000000000000000000000000000000000000000000"},
|
||||||
|
"staffTrained": 0,
|
||||||
|
"monitoringOwner": "REPLACE",
|
||||||
|
"rollbackOwner": "REPLACE",
|
||||||
|
"scenarios": [
|
||||||
|
{"id": "ai-suggestion-review", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "faq-positive-negative", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "faq-stop-control", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "knowledge-curation", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "monitoring-rollback", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "staff-training", "status": "not-run", "evidence": []}
|
||||||
|
],
|
||||||
|
"postAcceptanceState": {"faqMode": "off", "pmsWrites": "disabled", "paymentCreation": "disabled"}
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Validate restricted Gate B knowledge, AI and FAQ acceptance evidence."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import datetime as dt
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
import re
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
|
||||||
|
SCENARIOS = {
|
||||||
|
"knowledge-curation", "faq-positive-negative", "faq-stop-control",
|
||||||
|
"ai-suggestion-review", "staff-training", "monitoring-rollback",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def require(condition: bool, message: str) -> None:
|
||||||
|
if not condition:
|
||||||
|
raise ValueError(message)
|
||||||
|
|
||||||
|
|
||||||
|
def timestamp(value: object, field: str) -> dt.datetime:
|
||||||
|
require(isinstance(value, str) and value.endswith("Z"), f"{field} must be a UTC timestamp ending in Z.")
|
||||||
|
try:
|
||||||
|
return dt.datetime.fromisoformat(value.removesuffix("Z") + "+00:00")
|
||||||
|
except ValueError as error:
|
||||||
|
raise ValueError(f"{field} is not a valid timestamp.") from error
|
||||||
|
|
||||||
|
|
||||||
|
def name(value: object, field: str) -> str:
|
||||||
|
result = str(value or "").strip()
|
||||||
|
require(2 <= len(result) <= 120 and "@" not in result, f"{field} requires a name without an email address.")
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def refs(value: object, field: str) -> None:
|
||||||
|
require(isinstance(value, list) and 1 <= len(value) <= 10 and all(
|
||||||
|
isinstance(item, str) and 3 <= len(item) <= 200 and "@" not in item for item in value
|
||||||
|
), f"{field} requires safe opaque evidence references.")
|
||||||
|
|
||||||
|
|
||||||
|
def validate(record: object) -> None:
|
||||||
|
require(isinstance(record, dict), "Acceptance record must be a JSON object.")
|
||||||
|
require(record.get("schemaVersion") == 1, "Unsupported automation acceptance schema.")
|
||||||
|
require(record.get("system") == "guestops-automation-acceptance", "system must be guestops-automation-acceptance.")
|
||||||
|
require(record.get("targetGate") == "B", "Automation acceptance must target Gate B.")
|
||||||
|
require(record.get("dataClassification") == "synthetic-only", "Automation acceptance must use synthetic data only.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{40}", str(record.get("releaseCommit", ""))) is not None, "releaseCommit must be a full lowercase Git SHA.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{64}", str(record.get("releaseRecordSha256", ""))) is not None, "releaseRecordSha256 must be a SHA-256 digest.")
|
||||||
|
origin = urlparse(str(record.get("environment", "")))
|
||||||
|
require(origin.scheme == "https" and origin.hostname and origin.path in ("", "/") and not origin.query and not origin.fragment and origin.username is None and origin.password is None,
|
||||||
|
"environment must be an HTTPS origin without credentials, path, query or fragment.")
|
||||||
|
operator = name(record.get("operator"), "operator")
|
||||||
|
reviewer = name(record.get("reviewedBy"), "reviewedBy")
|
||||||
|
require(operator.casefold() != reviewer.casefold(), "operator and reviewedBy must be different people.")
|
||||||
|
started = timestamp(record.get("startedAt"), "startedAt")
|
||||||
|
ended = timestamp(record.get("endedAt"), "endedAt")
|
||||||
|
reviewed = timestamp(record.get("reviewedAt"), "reviewedAt")
|
||||||
|
require(started <= ended <= reviewed, "Acceptance timestamps are out of order.")
|
||||||
|
|
||||||
|
faq = record.get("faqEvaluation")
|
||||||
|
require(isinstance(faq, dict), "faqEvaluation is required.")
|
||||||
|
for field in ("positiveCases", "negativeCases"):
|
||||||
|
require(isinstance(faq.get(field), int) and not isinstance(faq.get(field), bool) and faq[field] > 0,
|
||||||
|
f"faqEvaluation.{field} must be a positive integer.")
|
||||||
|
require(faq.get("falsePositives") == 0 and faq.get("falseNegatives") == 0,
|
||||||
|
"FAQ activation requires zero false positives and zero false negatives.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{64}", str(faq.get("reportSha256", ""))) is not None,
|
||||||
|
"faqEvaluation.reportSha256 must identify the retained report.")
|
||||||
|
ai = record.get("aiEvaluation")
|
||||||
|
require(isinstance(ai, dict) and isinstance(ai.get("casesReviewed"), int) and not isinstance(ai.get("casesReviewed"), bool) and ai["casesReviewed"] > 0,
|
||||||
|
"aiEvaluation requires at least one reviewed case.")
|
||||||
|
require(isinstance(ai.get("unsafeDraftsApproved"), int) and not isinstance(ai.get("unsafeDraftsApproved"), bool)
|
||||||
|
and ai["unsafeDraftsApproved"] == 0, "No unsafe AI draft may be approved.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{64}", str(ai.get("reportSha256", ""))) is not None,
|
||||||
|
"aiEvaluation.reportSha256 must identify the retained report.")
|
||||||
|
require(isinstance(record.get("staffTrained"), int) and not isinstance(record.get("staffTrained"), bool) and record["staffTrained"] > 0,
|
||||||
|
"At least one pilot staff member must complete training.")
|
||||||
|
name(record.get("monitoringOwner"), "monitoringOwner")
|
||||||
|
name(record.get("rollbackOwner"), "rollbackOwner")
|
||||||
|
|
||||||
|
scenarios = record.get("scenarios")
|
||||||
|
require(isinstance(scenarios, list), "scenarios must be a list.")
|
||||||
|
ids = [item.get("id") for item in scenarios if isinstance(item, dict)]
|
||||||
|
require(len(ids) == len(scenarios) and len(ids) == len(set(ids)) and set(ids) == SCENARIOS,
|
||||||
|
"Acceptance record requires the exact automation scenario set.")
|
||||||
|
for item in scenarios:
|
||||||
|
require(item.get("status") == "pass", f"Scenario {item['id']} has not passed.")
|
||||||
|
refs(item.get("evidence"), f"Scenario {item['id']}")
|
||||||
|
require(record.get("postAcceptanceState") == {"faqMode": "off", "pmsWrites": "disabled", "paymentCreation": "disabled"},
|
||||||
|
"Acceptance must end with FAQ live mode, PMS writes and payment creation disabled.")
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument("record", type=Path)
|
||||||
|
args = parser.parse_args()
|
||||||
|
validate(json.loads(args.record.read_text(encoding="utf-8")))
|
||||||
|
print("Automation acceptance record is structurally complete. This validates the record, not its restricted evidence.")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except (OSError, ValueError, json.JSONDecodeError) as error:
|
||||||
|
print(f"Automation acceptance record rejected: {error}", file=__import__("sys").stderr)
|
||||||
|
raise SystemExit(1)
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"system": "guestops-desktop-parity",
|
||||||
|
"dataClassification": "synthetic-only",
|
||||||
|
"desktopBaselineCommit": "18b983bf402ecdded6430fd40bc4d3320587595a",
|
||||||
|
"releaseCommit": "0000000000000000000000000000000000000000",
|
||||||
|
"releaseRecordSha256": "0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"environment": "https://sandbox-guestops.example.invalid",
|
||||||
|
"browser": {
|
||||||
|
"name": "Microsoft Edge",
|
||||||
|
"version": "REPLACE_WITH_FULL_VERSION",
|
||||||
|
"operatingSystem": "Windows 11"
|
||||||
|
},
|
||||||
|
"viewport": {"width": 1440, "height": 900, "deviceScaleFactor": 1},
|
||||||
|
"hotelTimeZone": "Europe/London",
|
||||||
|
"operator": "Acceptance operator",
|
||||||
|
"reviewedBy": "Independent reviewer",
|
||||||
|
"startedAt": "2026-09-29T09:00:00Z",
|
||||||
|
"endedAt": "2026-09-29T10:00:00Z",
|
||||||
|
"reviewedAt": "2026-09-29T11:00:00Z",
|
||||||
|
"scenarios": [
|
||||||
|
{"id": "desktop-layout", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "draft-conversation-guard", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "draft-filter-search-guard", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "draft-route-history-reload-guard", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "inbox-core-workflow", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "pagination-beyond-500", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "role-and-control-parity", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "timezone-and-dst", "status": "not-run", "evidence": []}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Validate a restricted GuestOps desktop-parity acceptance record."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import datetime as dt
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
import re
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
|
||||||
|
DESKTOP_BASELINE = "18b983bf402ecdded6430fd40bc4d3320587595a"
|
||||||
|
SCENARIOS = {
|
||||||
|
"inbox-core-workflow",
|
||||||
|
"pagination-beyond-500",
|
||||||
|
"draft-conversation-guard",
|
||||||
|
"draft-filter-search-guard",
|
||||||
|
"draft-route-history-reload-guard",
|
||||||
|
"timezone-and-dst",
|
||||||
|
"role-and-control-parity",
|
||||||
|
"desktop-layout",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def require(condition: bool, message: str) -> None:
|
||||||
|
if not condition:
|
||||||
|
raise ValueError(message)
|
||||||
|
|
||||||
|
|
||||||
|
def timestamp(value: object, field: str) -> dt.datetime:
|
||||||
|
require(isinstance(value, str) and value.endswith("Z"), f"{field} must be a UTC timestamp ending in Z.")
|
||||||
|
try:
|
||||||
|
parsed = dt.datetime.fromisoformat(value.removesuffix("Z") + "+00:00")
|
||||||
|
except ValueError as error:
|
||||||
|
raise ValueError(f"{field} is not a valid timestamp.") from error
|
||||||
|
require(parsed.tzinfo == dt.timezone.utc, f"{field} must be UTC.")
|
||||||
|
return parsed
|
||||||
|
|
||||||
|
|
||||||
|
def safe_name(value: object, field: str) -> str:
|
||||||
|
name = str(value or "").strip()
|
||||||
|
require(2 <= len(name) <= 120 and "@" not in name, f"{field} requires a name without an email address.")
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
|
def validate(record: object) -> None:
|
||||||
|
require(isinstance(record, dict), "Acceptance record must be a JSON object.")
|
||||||
|
require(record.get("schemaVersion") == 1, "Unsupported acceptance record schema.")
|
||||||
|
require(record.get("system") == "guestops-desktop-parity",
|
||||||
|
"Acceptance record system must be guestops-desktop-parity.")
|
||||||
|
require(record.get("dataClassification") == "synthetic-only",
|
||||||
|
"Desktop acceptance must use synthetic data only.")
|
||||||
|
require(record.get("desktopBaselineCommit") == DESKTOP_BASELINE,
|
||||||
|
"desktopBaselineCommit must identify the reviewed desktop baseline.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{40}", str(record.get("releaseCommit", ""))) is not None,
|
||||||
|
"releaseCommit must be a full lowercase Git SHA.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{64}", str(record.get("releaseRecordSha256", ""))) is not None,
|
||||||
|
"releaseRecordSha256 must be a SHA-256 digest.")
|
||||||
|
|
||||||
|
origin = urlparse(str(record.get("environment", "")))
|
||||||
|
require(origin.scheme == "https" and origin.hostname and origin.path in ("", "/")
|
||||||
|
and not origin.query and not origin.fragment and origin.username is None and origin.password is None,
|
||||||
|
"environment must be an HTTPS origin without credentials, path, query or fragment.")
|
||||||
|
|
||||||
|
browser = record.get("browser")
|
||||||
|
require(isinstance(browser, dict) and set(browser) == {"name", "version", "operatingSystem"},
|
||||||
|
"browser must contain exactly name, version and operatingSystem.")
|
||||||
|
for field in ("name", "version", "operatingSystem"):
|
||||||
|
require(2 <= len(str(browser.get(field, "")).strip()) <= 120,
|
||||||
|
f"browser.{field} is required.")
|
||||||
|
viewport = record.get("viewport")
|
||||||
|
require(isinstance(viewport, dict) and set(viewport) == {"width", "height", "deviceScaleFactor"},
|
||||||
|
"viewport must contain exactly width, height and deviceScaleFactor.")
|
||||||
|
require(isinstance(viewport["width"], int) and not isinstance(viewport["width"], bool)
|
||||||
|
and 1280 <= viewport["width"] <= 7680, "Desktop viewport width must be between 1280 and 7680 pixels.")
|
||||||
|
require(isinstance(viewport["height"], int) and not isinstance(viewport["height"], bool)
|
||||||
|
and 720 <= viewport["height"] <= 4320, "Desktop viewport height must be between 720 and 4320 pixels.")
|
||||||
|
require(isinstance(viewport["deviceScaleFactor"], (int, float)) and not isinstance(viewport["deviceScaleFactor"], bool)
|
||||||
|
and 0.5 <= viewport["deviceScaleFactor"] <= 4, "deviceScaleFactor must be between 0.5 and 4.")
|
||||||
|
time_zone = str(record.get("hotelTimeZone", ""))
|
||||||
|
require(time_zone == "UTC" or re.fullmatch(r"[A-Za-z_]+(?:/[A-Za-z0-9_+\-]+)+", time_zone) is not None,
|
||||||
|
"hotelTimeZone must be UTC or an IANA timezone name.")
|
||||||
|
|
||||||
|
operator = safe_name(record.get("operator"), "operator")
|
||||||
|
reviewer = safe_name(record.get("reviewedBy"), "reviewedBy")
|
||||||
|
require(operator.casefold() != reviewer.casefold(), "operator and reviewedBy must be different people.")
|
||||||
|
started = timestamp(record.get("startedAt"), "startedAt")
|
||||||
|
ended = timestamp(record.get("endedAt"), "endedAt")
|
||||||
|
reviewed = timestamp(record.get("reviewedAt"), "reviewedAt")
|
||||||
|
require(started <= ended <= reviewed, "Acceptance timestamps are out of order.")
|
||||||
|
|
||||||
|
scenarios = record.get("scenarios")
|
||||||
|
require(isinstance(scenarios, list), "scenarios must be a list.")
|
||||||
|
ids = [item.get("id") for item in scenarios if isinstance(item, dict)]
|
||||||
|
require(len(ids) == len(scenarios) and len(ids) == len(set(ids)) and set(ids) == SCENARIOS,
|
||||||
|
"Acceptance record requires the exact desktop scenario set.")
|
||||||
|
for item in scenarios:
|
||||||
|
scenario_id = item["id"]
|
||||||
|
require(item.get("status") == "pass", f"Scenario {scenario_id} has not passed.")
|
||||||
|
evidence = item.get("evidence")
|
||||||
|
require(isinstance(evidence, list) and 1 <= len(evidence) <= 10 and all(
|
||||||
|
isinstance(value, str) and 3 <= len(value) <= 200 and "@" not in value for value in evidence
|
||||||
|
), f"Scenario {scenario_id} requires safe opaque evidence references without email addresses.")
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument("record", type=Path)
|
||||||
|
args = parser.parse_args()
|
||||||
|
validate(json.loads(args.record.read_text(encoding="utf-8")))
|
||||||
|
print(f"Desktop-parity acceptance record is structurally complete: {len(SCENARIOS)} scenarios passed. This validates the record, not its restricted evidence.")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except (OSError, ValueError, json.JSONDecodeError) as error:
|
||||||
|
print(f"Desktop-parity acceptance record rejected: {error}", file=__import__("sys").stderr)
|
||||||
|
raise SystemExit(1)
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"acceptedAt": "2026-01-01T00:00:00Z",
|
||||||
|
"acceptedBy": "REPLACE WITH APPROVER",
|
||||||
|
"endedAt": "2026-01-01T00:00:00Z",
|
||||||
|
"environment": "https://sandbox-guestops.futuresens.co.uk",
|
||||||
|
"mailboxLabel": "sandbox mailbox A",
|
||||||
|
"operator": "REPLACE WITH OPERATOR",
|
||||||
|
"releaseCommit": "0000000000000000000000000000000000000000",
|
||||||
|
"releaseRecordSha256": "0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"scenarios": [
|
||||||
|
{"id": "oauth-readonly", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "initial-import", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "duplicate-import", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "same-account-reconnect", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "different-account-rejected", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "provider-revocation", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "reviewed-send", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "gmail-threading", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "duplicate-approval", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "uncertain-send-reconciliation", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "sending-stop-control", "status": "not-run", "evidence": []}
|
||||||
|
],
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"startedAt": "2026-01-01T00:00:00Z",
|
||||||
|
"system": "google-mailbox"
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Validate a restricted Google mailbox acceptance record without reading its evidence."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import datetime as dt
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
|
||||||
|
SCENARIOS = {
|
||||||
|
"oauth-readonly",
|
||||||
|
"initial-import",
|
||||||
|
"duplicate-import",
|
||||||
|
"same-account-reconnect",
|
||||||
|
"different-account-rejected",
|
||||||
|
"provider-revocation",
|
||||||
|
"reviewed-send",
|
||||||
|
"gmail-threading",
|
||||||
|
"duplicate-approval",
|
||||||
|
"uncertain-send-reconciliation",
|
||||||
|
"sending-stop-control",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def require(condition: bool, message: str) -> None:
|
||||||
|
if not condition:
|
||||||
|
raise ValueError(message)
|
||||||
|
|
||||||
|
|
||||||
|
def utc_timestamp(value: object, field: str) -> dt.datetime:
|
||||||
|
require(isinstance(value, str) and value.endswith("Z"), f"{field} must be a UTC timestamp ending in Z.")
|
||||||
|
try:
|
||||||
|
parsed = dt.datetime.fromisoformat(value.removesuffix("Z") + "+00:00")
|
||||||
|
except ValueError as error:
|
||||||
|
raise ValueError(f"{field} is not a valid timestamp.") from error
|
||||||
|
require(parsed.tzinfo == dt.timezone.utc, f"{field} must be UTC.")
|
||||||
|
return parsed
|
||||||
|
|
||||||
|
|
||||||
|
def validate(report: object) -> None:
|
||||||
|
require(isinstance(report, dict), "Acceptance record must be a JSON object.")
|
||||||
|
require(report.get("schemaVersion") == 1, "Unsupported acceptance record schema.")
|
||||||
|
require(report.get("system") == "google-mailbox", "Acceptance record system must be google-mailbox.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{40}", str(report.get("releaseCommit", ""))) is not None,
|
||||||
|
"releaseCommit must be a full lowercase Git SHA.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{64}", str(report.get("releaseRecordSha256", ""))) is not None,
|
||||||
|
"releaseRecordSha256 must be a SHA-256 digest.")
|
||||||
|
|
||||||
|
environment = str(report.get("environment", ""))
|
||||||
|
parsed_url = urlparse(environment)
|
||||||
|
require(parsed_url.scheme == "https" and parsed_url.hostname and parsed_url.path in ("", "/") and not parsed_url.query and not parsed_url.fragment,
|
||||||
|
"environment must be an HTTPS origin without credentials, path, query or fragment.")
|
||||||
|
require(parsed_url.username is None and parsed_url.password is None, "environment must not contain credentials.")
|
||||||
|
|
||||||
|
mailbox_label = str(report.get("mailboxLabel", ""))
|
||||||
|
require(3 <= len(mailbox_label) <= 80 and "@" not in mailbox_label,
|
||||||
|
"mailboxLabel must be a short non-email alias; do not put mailbox addresses in the record.")
|
||||||
|
require(2 <= len(str(report.get("operator", ""))) <= 120, "operator is required.")
|
||||||
|
started = utc_timestamp(report.get("startedAt"), "startedAt")
|
||||||
|
ended = utc_timestamp(report.get("endedAt"), "endedAt")
|
||||||
|
accepted = utc_timestamp(report.get("acceptedAt"), "acceptedAt")
|
||||||
|
require(started <= ended <= accepted, "Acceptance timestamps are out of order.")
|
||||||
|
require(2 <= len(str(report.get("acceptedBy", ""))) <= 120, "acceptedBy is required.")
|
||||||
|
|
||||||
|
scenarios = report.get("scenarios")
|
||||||
|
require(isinstance(scenarios, list), "scenarios must be a list.")
|
||||||
|
ids = [item.get("id") for item in scenarios if isinstance(item, dict)]
|
||||||
|
require(len(ids) == len(scenarios) and len(ids) == len(set(ids)), "Scenario IDs must be unique objects.")
|
||||||
|
require(set(ids) == SCENARIOS, "Acceptance record does not contain the exact required scenario set.")
|
||||||
|
for item in scenarios:
|
||||||
|
scenario_id = item["id"]
|
||||||
|
require(item.get("status") == "pass", f"Scenario {scenario_id} has not passed.")
|
||||||
|
evidence = item.get("evidence")
|
||||||
|
require(isinstance(evidence, list) and 1 <= len(evidence) <= 10,
|
||||||
|
f"Scenario {scenario_id} requires one to ten restricted evidence references.")
|
||||||
|
require(all(isinstance(value, str) and 3 <= len(value) <= 200 and "@" not in value for value in evidence),
|
||||||
|
f"Scenario {scenario_id} has an invalid evidence reference; do not include email addresses or raw evidence.")
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument("record", type=Path)
|
||||||
|
args = parser.parse_args()
|
||||||
|
report = json.loads(args.record.read_text(encoding="utf-8"))
|
||||||
|
validate(report)
|
||||||
|
print(f"Google acceptance record is structurally complete: {len(SCENARIOS)} scenarios passed. This validates the record, not the underlying provider evidence.")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except (OSError, json.JSONDecodeError, ValueError) as error:
|
||||||
|
print(f"Google acceptance record rejected: {error}", file=__import__("sys").stderr)
|
||||||
|
raise SystemExit(1)
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"system": "guestops-identity-privacy",
|
||||||
|
"targetGate": "B",
|
||||||
|
"releaseCommit": "0000000000000000000000000000000000000000",
|
||||||
|
"releaseRecordSha256": "0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"environment": "https://sandbox-guestops.example.invalid",
|
||||||
|
"operator": "REPLACE OPERATOR",
|
||||||
|
"reviewedBy": "REPLACE REVIEWER",
|
||||||
|
"startedAt": "2026-10-01T09:00:00Z",
|
||||||
|
"endedAt": "2026-10-01T10:00:00Z",
|
||||||
|
"reviewedAt": "2026-10-01T11:00:00Z",
|
||||||
|
"retention": {
|
||||||
|
"conversationDays": 0,
|
||||||
|
"auditDays": 0,
|
||||||
|
"backupDays": 0,
|
||||||
|
"accountDays": 0,
|
||||||
|
"privacyOwner": "REPLACE",
|
||||||
|
"deletionOwner": "REPLACE",
|
||||||
|
"legalHoldOwner": "REPLACE",
|
||||||
|
"deletionProcedure": "REPLACE-RESTRICTED-REFERENCE",
|
||||||
|
"legalHoldProcedure": "REPLACE-RESTRICTED-REFERENCE"
|
||||||
|
},
|
||||||
|
"providers": {
|
||||||
|
"google": {"status": "pending", "evidence": []},
|
||||||
|
"openai": {"status": "pending", "evidence": []}
|
||||||
|
},
|
||||||
|
"preferencesReviewed": [],
|
||||||
|
"scenarios": [
|
||||||
|
{"id": "account-lifecycle", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "audit-review", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "backup-retention", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "data-inventory", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "known-identity-limitations", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "login-throttling", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "preference-coverage", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "provider-processing", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "retention-deletion", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "role-boundaries", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "session-invalidation", "status": "not-run", "evidence": []}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Validate restricted Gate B identity, preference and privacy acceptance evidence."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import datetime as dt
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
import re
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
|
||||||
|
SCENARIOS = {
|
||||||
|
"role-boundaries", "account-lifecycle", "login-throttling", "session-invalidation",
|
||||||
|
"preference-coverage", "data-inventory", "retention-deletion", "backup-retention",
|
||||||
|
"provider-processing", "audit-review", "known-identity-limitations",
|
||||||
|
}
|
||||||
|
PREFERENCES = {
|
||||||
|
"hotel-name", "timezone", "signature", "ai-drafts", "staff-sending",
|
||||||
|
"faq-mode", "pms-updates", "payment-creation",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def require(condition: bool, message: str) -> None:
|
||||||
|
if not condition:
|
||||||
|
raise ValueError(message)
|
||||||
|
|
||||||
|
|
||||||
|
def timestamp(value: object, field: str) -> dt.datetime:
|
||||||
|
require(isinstance(value, str) and value.endswith("Z"), f"{field} must be a UTC timestamp ending in Z.")
|
||||||
|
try:
|
||||||
|
return dt.datetime.fromisoformat(value.removesuffix("Z") + "+00:00")
|
||||||
|
except ValueError as error:
|
||||||
|
raise ValueError(f"{field} is not a valid timestamp.") from error
|
||||||
|
|
||||||
|
|
||||||
|
def name(value: object, field: str) -> str:
|
||||||
|
result = str(value or "").strip()
|
||||||
|
require(2 <= len(result) <= 120 and "@" not in result, f"{field} requires a name without an email address.")
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def refs(value: object, field: str) -> None:
|
||||||
|
require(isinstance(value, list) and 1 <= len(value) <= 10 and all(
|
||||||
|
isinstance(item, str) and 3 <= len(item) <= 200 and "@" not in item for item in value
|
||||||
|
), f"{field} requires safe opaque evidence references.")
|
||||||
|
|
||||||
|
|
||||||
|
def validate(record: object) -> None:
|
||||||
|
require(isinstance(record, dict), "Acceptance record must be a JSON object.")
|
||||||
|
require(record.get("schemaVersion") == 1, "Unsupported identity/privacy acceptance schema.")
|
||||||
|
require(record.get("system") == "guestops-identity-privacy", "system must be guestops-identity-privacy.")
|
||||||
|
require(record.get("targetGate") == "B", "Identity/privacy acceptance must target Gate B.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{40}", str(record.get("releaseCommit", ""))) is not None, "releaseCommit must be a full lowercase Git SHA.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{64}", str(record.get("releaseRecordSha256", ""))) is not None, "releaseRecordSha256 must be a SHA-256 digest.")
|
||||||
|
origin = urlparse(str(record.get("environment", "")))
|
||||||
|
require(origin.scheme == "https" and origin.hostname and origin.path in ("", "/") and not origin.query and not origin.fragment and origin.username is None and origin.password is None,
|
||||||
|
"environment must be an HTTPS origin without credentials, path, query or fragment.")
|
||||||
|
operator = name(record.get("operator"), "operator")
|
||||||
|
reviewer = name(record.get("reviewedBy"), "reviewedBy")
|
||||||
|
require(operator.casefold() != reviewer.casefold(), "operator and reviewedBy must be different people.")
|
||||||
|
started = timestamp(record.get("startedAt"), "startedAt")
|
||||||
|
ended = timestamp(record.get("endedAt"), "endedAt")
|
||||||
|
reviewed = timestamp(record.get("reviewedAt"), "reviewedAt")
|
||||||
|
require(started <= ended <= reviewed, "Acceptance timestamps are out of order.")
|
||||||
|
|
||||||
|
retention = record.get("retention")
|
||||||
|
require(isinstance(retention, dict), "retention decisions are required.")
|
||||||
|
for field in ("conversationDays", "auditDays", "backupDays", "accountDays"):
|
||||||
|
value = retention.get(field)
|
||||||
|
require(isinstance(value, int) and not isinstance(value, bool) and 1 <= value <= 3650,
|
||||||
|
f"retention.{field} must be between 1 and 3650 days.")
|
||||||
|
for field in ("privacyOwner", "deletionOwner", "legalHoldOwner"):
|
||||||
|
name(retention.get(field), f"retention.{field}")
|
||||||
|
for field in ("deletionProcedure", "legalHoldProcedure"):
|
||||||
|
refs([retention.get(field)], f"retention.{field}")
|
||||||
|
|
||||||
|
providers = record.get("providers")
|
||||||
|
require(isinstance(providers, dict) and set(providers) == {"google", "openai"},
|
||||||
|
"providers must contain exactly google and openai decisions.")
|
||||||
|
require(all(isinstance(decision, dict) for decision in providers.values()),
|
||||||
|
"Each provider decision must be an object.")
|
||||||
|
require(providers["google"].get("status") == "accepted", "Google processing must be accepted for the Gate B mailbox pilot.")
|
||||||
|
require(providers["openai"].get("status") in ("accepted", "disabled"), "OpenAI processing must be accepted or disabled.")
|
||||||
|
for provider, decision in providers.items():
|
||||||
|
refs(decision.get("evidence"), f"Provider {provider}")
|
||||||
|
preferences = record.get("preferencesReviewed")
|
||||||
|
require(isinstance(preferences, list) and all(isinstance(item, str) for item in preferences)
|
||||||
|
and set(preferences) == PREFERENCES and len(preferences) == len(PREFERENCES),
|
||||||
|
"preferencesReviewed must contain the exact owner-controlled preference set.")
|
||||||
|
|
||||||
|
scenarios = record.get("scenarios")
|
||||||
|
require(isinstance(scenarios, list), "scenarios must be a list.")
|
||||||
|
ids = [item.get("id") for item in scenarios if isinstance(item, dict)]
|
||||||
|
require(len(ids) == len(scenarios) and len(ids) == len(set(ids)) and set(ids) == SCENARIOS,
|
||||||
|
"Acceptance record requires the exact identity/privacy scenario set.")
|
||||||
|
for item in scenarios:
|
||||||
|
require(item.get("status") == "pass", f"Scenario {item['id']} has not passed.")
|
||||||
|
refs(item.get("evidence"), f"Scenario {item['id']}")
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument("record", type=Path)
|
||||||
|
args = parser.parse_args()
|
||||||
|
validate(json.loads(args.record.read_text(encoding="utf-8")))
|
||||||
|
print("Identity/privacy acceptance record is structurally complete. This validates the record, not its restricted evidence or legal decisions.")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except (OSError, ValueError, json.JSONDecodeError) as error:
|
||||||
|
print(f"Identity/privacy acceptance record rejected: {error}", file=__import__("sys").stderr)
|
||||||
|
raise SystemExit(1)
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"system": "guestops-incident-exercise",
|
||||||
|
"targetGate": "B",
|
||||||
|
"dataClassification": "synthetic-only",
|
||||||
|
"releaseCommit": "0000000000000000000000000000000000000000",
|
||||||
|
"releaseRecordSha256": "0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"environment": "https://sandbox-guestops.example.invalid",
|
||||||
|
"operator": "Exercise operator",
|
||||||
|
"incidentCommander": "Incident commander",
|
||||||
|
"reviewedBy": "Independent reviewer",
|
||||||
|
"startedAt": "2026-09-29T09:00:00Z",
|
||||||
|
"endedAt": "2026-09-29T10:00:00Z",
|
||||||
|
"reviewedAt": "2026-09-29T11:00:00Z",
|
||||||
|
"targetsMinutes": {
|
||||||
|
"detection": 10,
|
||||||
|
"containment": 20,
|
||||||
|
"recovery": 60
|
||||||
|
},
|
||||||
|
"observedMinutes": {
|
||||||
|
"detection": 0,
|
||||||
|
"containment": 0,
|
||||||
|
"recovery": 0
|
||||||
|
},
|
||||||
|
"scenarios": [
|
||||||
|
{"id": "alert-and-escalate", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "controlled-recovery", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "disable-worker-writes", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "google-uncertain-send", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "image-rollback", "status": "not-run", "evidence": []},
|
||||||
|
{"id": "restore-readiness", "status": "not-run", "evidence": []}
|
||||||
|
],
|
||||||
|
"postExerciseState": {
|
||||||
|
"externalWrites": "disabled",
|
||||||
|
"faqMode": "off",
|
||||||
|
"unresolvedOperations": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Validate a restricted GuestOps incident and rollback exercise record."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import datetime as dt
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
import re
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
|
||||||
|
GATE_B_SCENARIOS = {
|
||||||
|
"alert-and-escalate",
|
||||||
|
"disable-worker-writes",
|
||||||
|
"google-uncertain-send",
|
||||||
|
"restore-readiness",
|
||||||
|
"image-rollback",
|
||||||
|
"controlled-recovery",
|
||||||
|
}
|
||||||
|
GATE_C_SCENARIOS = GATE_B_SCENARIOS | {
|
||||||
|
"pms-ambiguous-write",
|
||||||
|
"payment-ambiguous-create",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def require(condition: bool, message: str) -> None:
|
||||||
|
if not condition:
|
||||||
|
raise ValueError(message)
|
||||||
|
|
||||||
|
|
||||||
|
def utc_timestamp(value: object, field: str) -> dt.datetime:
|
||||||
|
require(isinstance(value, str) and value.endswith("Z"), f"{field} must be a UTC timestamp ending in Z.")
|
||||||
|
try:
|
||||||
|
parsed = dt.datetime.fromisoformat(value.removesuffix("Z") + "+00:00")
|
||||||
|
except ValueError as error:
|
||||||
|
raise ValueError(f"{field} is not a valid timestamp.") from error
|
||||||
|
require(parsed.tzinfo == dt.timezone.utc, f"{field} must be UTC.")
|
||||||
|
return parsed
|
||||||
|
|
||||||
|
|
||||||
|
def safe_name(value: object, field: str) -> str:
|
||||||
|
name = str(value or "").strip()
|
||||||
|
require(2 <= len(name) <= 120 and "@" not in name, f"{field} requires a name without an email address.")
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
|
def validate(record: object) -> None:
|
||||||
|
require(isinstance(record, dict), "Exercise record must be a JSON object.")
|
||||||
|
require(record.get("schemaVersion") == 1, "Unsupported exercise record schema.")
|
||||||
|
require(record.get("system") == "guestops-incident-exercise",
|
||||||
|
"Exercise record system must be guestops-incident-exercise.")
|
||||||
|
gate = record.get("targetGate")
|
||||||
|
require(gate in ("B", "C"), "targetGate must be B or C.")
|
||||||
|
require(record.get("dataClassification") == "synthetic-only",
|
||||||
|
"Incident exercises must use synthetic data only.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{40}", str(record.get("releaseCommit", ""))) is not None,
|
||||||
|
"releaseCommit must be a full lowercase Git SHA.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{64}", str(record.get("releaseRecordSha256", ""))) is not None,
|
||||||
|
"releaseRecordSha256 must be a SHA-256 digest.")
|
||||||
|
|
||||||
|
environment = str(record.get("environment", ""))
|
||||||
|
parsed_url = urlparse(environment)
|
||||||
|
require(parsed_url.scheme == "https" and parsed_url.hostname and parsed_url.path in ("", "/")
|
||||||
|
and not parsed_url.query and not parsed_url.fragment and parsed_url.username is None
|
||||||
|
and parsed_url.password is None,
|
||||||
|
"environment must be an HTTPS origin without credentials, path, query or fragment.")
|
||||||
|
|
||||||
|
operator = safe_name(record.get("operator"), "operator")
|
||||||
|
commander = safe_name(record.get("incidentCommander"), "incidentCommander")
|
||||||
|
reviewer = safe_name(record.get("reviewedBy"), "reviewedBy")
|
||||||
|
require(len({operator.casefold(), commander.casefold(), reviewer.casefold()}) == 3,
|
||||||
|
"operator, incidentCommander and reviewedBy must be different people.")
|
||||||
|
|
||||||
|
started = utc_timestamp(record.get("startedAt"), "startedAt")
|
||||||
|
ended = utc_timestamp(record.get("endedAt"), "endedAt")
|
||||||
|
reviewed = utc_timestamp(record.get("reviewedAt"), "reviewedAt")
|
||||||
|
require(started <= ended <= reviewed, "Exercise timestamps are out of order.")
|
||||||
|
|
||||||
|
targets = record.get("targetsMinutes")
|
||||||
|
observed = record.get("observedMinutes")
|
||||||
|
require(isinstance(targets, dict) and isinstance(observed, dict),
|
||||||
|
"targetsMinutes and observedMinutes are required.")
|
||||||
|
metric_keys = {"detection", "containment", "recovery"}
|
||||||
|
require(set(targets) == metric_keys and set(observed) == metric_keys,
|
||||||
|
"Timing records require exactly detection, containment and recovery.")
|
||||||
|
for metric in sorted(metric_keys):
|
||||||
|
target = targets[metric]
|
||||||
|
actual = observed[metric]
|
||||||
|
require(isinstance(target, (int, float)) and not isinstance(target, bool) and 0 < target <= 1440,
|
||||||
|
f"{metric} target must be greater than zero and no more than 1440 minutes.")
|
||||||
|
require(isinstance(actual, (int, float)) and not isinstance(actual, bool) and 0 <= actual <= target,
|
||||||
|
f"Observed {metric} time must meet its pre-agreed target.")
|
||||||
|
|
||||||
|
scenarios = record.get("scenarios")
|
||||||
|
require(isinstance(scenarios, list), "scenarios must be a list.")
|
||||||
|
ids = [item.get("id") for item in scenarios if isinstance(item, dict)]
|
||||||
|
required = GATE_C_SCENARIOS if gate == "C" else GATE_B_SCENARIOS
|
||||||
|
require(len(ids) == len(scenarios) and len(ids) == len(set(ids)) and set(ids) == required,
|
||||||
|
f"Gate {gate} requires the exact incident scenario set.")
|
||||||
|
for item in scenarios:
|
||||||
|
scenario_id = item["id"]
|
||||||
|
require(item.get("status") == "pass", f"Scenario {scenario_id} has not passed.")
|
||||||
|
evidence = item.get("evidence")
|
||||||
|
require(isinstance(evidence, list) and 1 <= len(evidence) <= 10 and all(
|
||||||
|
isinstance(value, str) and 3 <= len(value) <= 200 and "@" not in value
|
||||||
|
for value in evidence
|
||||||
|
), f"Scenario {scenario_id} requires safe opaque evidence references without email addresses.")
|
||||||
|
|
||||||
|
final_state = record.get("postExerciseState")
|
||||||
|
require(isinstance(final_state, dict) and final_state == {
|
||||||
|
"externalWrites": "disabled",
|
||||||
|
"faqMode": "off",
|
||||||
|
"unresolvedOperations": 0,
|
||||||
|
}, "Exercise must end with writes disabled, FAQ mode off and no unresolved operations.")
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument("record", type=Path)
|
||||||
|
args = parser.parse_args()
|
||||||
|
validate(json.loads(args.record.read_text(encoding="utf-8")))
|
||||||
|
print("Incident exercise record is structurally complete and passed. This validates the record, not its restricted evidence.")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except (OSError, ValueError, json.JSONDecodeError) as error:
|
||||||
|
print(f"Incident exercise record rejected: {error}", file=__import__("sys").stderr)
|
||||||
|
raise SystemExit(1)
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
const guestops = db.getSiblingDB('guestops');
|
|
||||||
guestops.createUser({user: 'guestops', pwd: process.env.MONGO_APP_PASSWORD, roles: [{role: 'readWrite', db: 'guestops'}]});
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
# Install within the existing Nginx configuration. Obtain the certificate first.
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name sandbox-guestops.futuresens.co.uk;
|
|
||||||
location /.well-known/acme-challenge/ { root /var/www/letsencrypt; }
|
|
||||||
location / { return 301 https://$host$request_uri; }
|
|
||||||
}
|
|
||||||
server {
|
|
||||||
listen 443 ssl;
|
|
||||||
server_name sandbox-guestops.futuresens.co.uk;
|
|
||||||
ssl_certificate /etc/letsencrypt/live/sandbox-guestops.futuresens.co.uk/fullchain.pem;
|
|
||||||
ssl_certificate_key /etc/letsencrypt/live/sandbox-guestops.futuresens.co.uk/privkey.pem;
|
|
||||||
ssl_protocols TLSv1.2 TLSv1.3;
|
|
||||||
add_header Strict-Transport-Security "max-age=31536000" always;
|
|
||||||
client_max_body_size 128k;
|
|
||||||
# OAuth authorization codes and state must not appear in access logs.
|
|
||||||
location = /api/integrations/google/callback {
|
|
||||||
access_log off;
|
|
||||||
proxy_pass http://127.0.0.1:8080;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Forwarded-Proto https;
|
|
||||||
}
|
|
||||||
location / {
|
|
||||||
proxy_pass http://127.0.0.1:8080;
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Forwarded-Proto https;
|
|
||||||
proxy_set_header X-Forwarded-For $remote_addr;
|
|
||||||
proxy_read_timeout 60s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-258
@@ -1,258 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""GuestOps dedicated-Compose operations. Never prints credentials or provider data."""
|
|
||||||
import argparse
|
|
||||||
import contextlib
|
|
||||||
import hashlib
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
|
||||||
import re
|
|
||||||
import shutil
|
|
||||||
import stat
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
import tarfile
|
|
||||||
import tempfile
|
|
||||||
import time
|
|
||||||
import urllib.request
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
ROOT = Path(__file__).resolve().parents[1]
|
|
||||||
FILES = {"mongo.archive.gz", "keys.tar.gz", "configuration.json", "manifest.json"}
|
|
||||||
LIMIT = 8 * 1024**3
|
|
||||||
|
|
||||||
|
|
||||||
def require(condition, message):
|
|
||||||
if not condition:
|
|
||||||
raise RuntimeError(message)
|
|
||||||
|
|
||||||
|
|
||||||
def run(args, *, output=None, input_file=None, timeout=900):
|
|
||||||
# Provider output may contain secrets; errors identify only the program.
|
|
||||||
result = subprocess.run(args, cwd=ROOT, stdin=input_file or subprocess.DEVNULL,
|
|
||||||
stdout=output or subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout)
|
|
||||||
require(result.returncode == 0, f"{args[0]} step failed. Check the private operator environment; no command output was logged.")
|
|
||||||
return result.stdout or b""
|
|
||||||
|
|
||||||
|
|
||||||
def compose(*args, **kwargs):
|
|
||||||
return run(["docker", "compose", *args], **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
def digest(path):
|
|
||||||
with path.open("rb") as stream:
|
|
||||||
return hashlib.file_digest(stream, "sha256").hexdigest()
|
|
||||||
|
|
||||||
|
|
||||||
def image_id(image):
|
|
||||||
require(not image.startswith("-"), "Invalid image reference.")
|
|
||||||
return run(["docker", "image", "inspect", "--format", "{{.Id}}", image]).decode().strip()
|
|
||||||
|
|
||||||
|
|
||||||
def provider_configured(config, target):
|
|
||||||
section = "Pms" if target == "/run/guestops/pms.json" else "Payments"
|
|
||||||
# Only the exact shipped empty template is public; unknown settings fail closed.
|
|
||||||
return config not in ({}, {section: {"Hotels": {}}})
|
|
||||||
|
|
||||||
|
|
||||||
AUTH = 'const c=new Mongo("mongodb://127.0.0.1"); c.getDB("admin").auth(process.env.MONGO_INITDB_ROOT_USERNAME,process.env.MONGO_INITDB_ROOT_PASSWORD);'
|
|
||||||
INVENTORY = 'const d=c.getDB("guestops"); print(JSON.stringify({bytes:d.stats().storageSize+d.stats().indexSize,collections:Object.fromEntries(d.getCollectionNames().filter(n=>!n.startsWith("system.")).sort().map(n=>[n,{count:d.getCollection(n).countDocuments({}),indexes:d.getCollection(n).getIndexes().map(i=>{delete i.ns;return i;}).sort((a,b)=>a.name.localeCompare(b.name))}]))}));'
|
|
||||||
|
|
||||||
|
|
||||||
def mongo(script):
|
|
||||||
return compose("exec", "-T", "mongo", "mongosh", "--quiet", "--nodb", "--eval", AUTH + script)
|
|
||||||
|
|
||||||
|
|
||||||
def configuration():
|
|
||||||
config = json.loads(compose("config", "--format", "json"))
|
|
||||||
services = config["services"]
|
|
||||||
require(set(services) == {"api", "worker", "mongo"}, "This tool supports the dedicated three-service GuestOps Compose deployment only.")
|
|
||||||
require(not services["mongo"].get("ports"), "MongoDB must not have published ports.")
|
|
||||||
ports = services["api"].get("ports", [])
|
|
||||||
require(len(ports) == 1 and ports[0].get("host_ip") == "127.0.0.1" and int(ports[0]["target"]) == 8080, "API must publish only port 8080 on loopback.")
|
|
||||||
require(not services["worker"].get("ports"), "Worker must not publish ports.")
|
|
||||||
for name in ("api", "worker"):
|
|
||||||
env = services[name]["environment"]
|
|
||||||
require(env.get("Mongo__Database") == "guestops" and "@mongo:27017/guestops?" in env.get("Mongo__ConnectionString", ""), "Backup supports only the dedicated Compose guestops database.")
|
|
||||||
require(str(env.get("Preview", "false")).lower() != "true", "Production preview is forbidden.")
|
|
||||||
require(env.get("Keys__Path") == "/var/lib/guestops/keys", "Unexpected key directory.")
|
|
||||||
require(services["api"]["environment"].get("ASPNETCORE_ENVIRONMENT") == "Production", "API must use Production environment.")
|
|
||||||
require(re.fullmatch(r"https://[A-Za-z0-9.-]+", services["api"]["environment"].get("PublicUrl", "")), "PublicUrl must be an HTTPS hostname without a path.")
|
|
||||||
key_sources = []
|
|
||||||
for name in ("api", "worker"):
|
|
||||||
keys = [v for v in services[name].get("volumes", []) if v["target"] == "/var/lib/guestops/keys"]
|
|
||||||
require(len(keys) == 1 and keys[0]["type"] == "volume", "API and worker require a shared persistent key volume.")
|
|
||||||
key_sources.append(keys[0]["source"])
|
|
||||||
require(key_sources[0] == key_sources[1], "API and worker key volumes differ.")
|
|
||||||
return config
|
|
||||||
|
|
||||||
|
|
||||||
def preflight(args):
|
|
||||||
config = configuration()
|
|
||||||
env_file = ROOT / ".env"
|
|
||||||
require(env_file.is_file() and not env_file.is_symlink(), "Create a private .env file before deployment.")
|
|
||||||
require(stat.S_IMODE(env_file.stat().st_mode) & 0o077 == 0, ".env must not be accessible to group or other users.")
|
|
||||||
require(shutil.disk_usage(ROOT).free >= 8 * 1024**3, "Keep at least 8 GiB free before deployment; allow extra room for backups.")
|
|
||||||
for name, service in config["services"].items():
|
|
||||||
image_id(service["image"])
|
|
||||||
for volume in service.get("volumes", []):
|
|
||||||
if volume["type"] == "bind":
|
|
||||||
require(Path(volume["source"]).exists(), f"A required {name} bind mount is missing.")
|
|
||||||
if volume["target"] in ("/run/guestops/pms.json", "/run/guestops/payments.json"):
|
|
||||||
provider = Path(volume["source"])
|
|
||||||
if provider_configured(json.loads(provider.read_text()), volume["target"]):
|
|
||||||
require(stat.S_IMODE(provider.stat().st_mode) & 0o077 == 0, "Configured provider files must not be accessible to group or other users.")
|
|
||||||
if not args.offline:
|
|
||||||
url = config["services"]["api"]["environment"]["PublicUrl"]
|
|
||||||
require(re.fullmatch(r"https://[A-Za-z0-9.-]+", url), "PublicUrl must be an HTTPS hostname without a path.")
|
|
||||||
with urllib.request.urlopen(url + "/health/ready", timeout=15) as response:
|
|
||||||
require(response.url == url + "/health/ready" and json.load(response) == {"status": "ready"}, "Public HTTPS readiness failed.")
|
|
||||||
print("Preflight passed: private database, loopback API, production settings, images, mounts and disk headroom" + ("; HTTPS not checked." if args.offline else "; public HTTPS and database readiness checked."))
|
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
|
||||||
def maintenance_lock():
|
|
||||||
import fcntl
|
|
||||||
with (ROOT / ".guestops-maintenance.lock").open("a") as lock:
|
|
||||||
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
def backup(args):
|
|
||||||
require(args.confirm_maintenance, "Backup requires --confirm-maintenance: API and workers will briefly stop.")
|
|
||||||
require(re.fullmatch(r"[A-Fa-f0-9]{40}", args.recipient), "Use a verified full 40-character GPG recipient fingerprint.")
|
|
||||||
run(["gpg", "--batch", "--list-keys", args.recipient])
|
|
||||||
destination = Path(args.output).resolve()
|
|
||||||
require(not destination.exists(), "Backup output already exists; choose a new filename.")
|
|
||||||
require(destination.parent.is_dir(), "Create the private backup directory first.")
|
|
||||||
require(stat.S_IMODE(destination.parent.stat().st_mode) & 0o077 == 0, "Backup directory must be private (mode 700).")
|
|
||||||
config = configuration()
|
|
||||||
runtime = {}
|
|
||||||
for service in ("api", "worker", "mongo"):
|
|
||||||
cid = compose("ps", "--status", "running", "-q", service).decode().strip()
|
|
||||||
require(re.fullmatch(r"[a-f0-9]{12,64}", cid), f"Exactly one running {service} container is required.")
|
|
||||||
runtime[service] = json.loads(run(["docker", "inspect", cid]))[0]
|
|
||||||
require(shutil.disk_usage(destination.parent).free >= 3 * json.loads(mongo(INVENTORY))["bytes"] + 1024**3, "Insufficient free space for a consistent encrypted backup.")
|
|
||||||
partial = destination.with_name(destination.name + ".partial-" + uuid.uuid4().hex)
|
|
||||||
with maintenance_lock(), tempfile.TemporaryDirectory(prefix="guestops-backup-", dir=destination.parent) as folder:
|
|
||||||
folder = Path(folder)
|
|
||||||
stopped = False
|
|
||||||
ttl = None
|
|
||||||
try:
|
|
||||||
# Set before stopping so partial stop failures also attempt recovery.
|
|
||||||
stopped = True
|
|
||||||
compose("stop", "-t", "150", "api", "worker")
|
|
||||||
ttl = json.loads(mongo('print(JSON.stringify(c.getDB("admin").runCommand({getParameter:1,ttlMonitorEnabled:1}).ttlMonitorEnabled));'))
|
|
||||||
require(isinstance(ttl, bool), "Cannot determine MongoDB TTL monitor state.")
|
|
||||||
mongo('const r=c.getDB("admin").runCommand({setParameter:1,ttlMonitorEnabled:false});if(!r.ok)quit(1);')
|
|
||||||
inventory = json.loads(mongo(INVENTORY))
|
|
||||||
dump = 'set -eu; case "$MONGO_INITDB_ROOT_PASSWORD" in ""|*[!0-9a-fA-F]*) exit 1;; esac; umask 077; cfg=$(mktemp); trap \'rm -f "$cfg"\' EXIT; printf \'password: "%s"\\n\' "$MONGO_INITDB_ROOT_PASSWORD" > "$cfg"; mongodump --config "$cfg" --username "$MONGO_INITDB_ROOT_USERNAME" --authenticationDatabase admin --db guestops --archive --gzip'
|
|
||||||
with (folder / "mongo.archive.gz").open("wb") as output:
|
|
||||||
compose("exec", "-T", "mongo", "sh", "-c", dump, output=output)
|
|
||||||
probe = compose("run", "--rm", "--no-deps", "-T", "-e", "Logging__LogLevel__Default=None", "api", "--backup-probe").decode().strip()
|
|
||||||
require(re.fullmatch(r"[A-Za-z0-9_-]{20,4096}", probe), "Key probe did not return a valid protected value.")
|
|
||||||
with (folder / "keys.tar.gz").open("wb") as output:
|
|
||||||
compose("run", "--rm", "--no-deps", "-T", "--entrypoint", "tar", "api", "-C", "/var/lib/guestops/keys", "-czf", "-", ".", output=output)
|
|
||||||
mounted = {}
|
|
||||||
for volume in config["services"]["api"].get("volumes", []):
|
|
||||||
if volume["type"] == "bind" and volume["target"] in ("/run/guestops/pms.json", "/run/guestops/payments.json"):
|
|
||||||
mounted[volume["target"]] = Path(volume["source"]).read_text()
|
|
||||||
(folder / "configuration.json").write_text(json.dumps({"compose": config, "runtime": runtime, "providerFiles": mounted}))
|
|
||||||
manifest = {"format": 1, "createdAt": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), "inventory": inventory, "probe": probe, "apiImageId": runtime["api"]["Image"], "mongoImageId": runtime["mongo"]["Image"], "sha256": {name: digest(folder / name) for name in FILES - {"manifest.json"}}}
|
|
||||||
(folder / "manifest.json").write_text(json.dumps(manifest))
|
|
||||||
finally:
|
|
||||||
try:
|
|
||||||
if ttl is not None:
|
|
||||||
mongo('const r=c.getDB("admin").runCommand({setParameter:1,ttlMonitorEnabled:' + str(ttl).lower() + '});if(!r.ok)quit(1);')
|
|
||||||
finally:
|
|
||||||
if stopped:
|
|
||||||
compose("start", "api", "worker")
|
|
||||||
try:
|
|
||||||
with tarfile.open(folder / "bundle.tar", "w") as archive:
|
|
||||||
for name in sorted(FILES):
|
|
||||||
archive.add(folder / name, arcname=name, recursive=False)
|
|
||||||
run(["gpg", "--batch", "--trust-model", "always", "--recipient", args.recipient, "--output", str(partial), "--encrypt", str(folder / "bundle.tar")])
|
|
||||||
os.link(partial, destination) # Atomic publication, never overwrite an existing backup.
|
|
||||||
finally:
|
|
||||||
partial.unlink(missing_ok=True)
|
|
||||||
print("Encrypted backup complete. Copy it off-server and perform a restore drill.")
|
|
||||||
|
|
||||||
|
|
||||||
def unpack(bundle, folder):
|
|
||||||
with tarfile.open(bundle, "r:") as archive:
|
|
||||||
members = archive.getmembers()
|
|
||||||
require(len(members) == len(FILES) and {m.name for m in members} == FILES, "Unexpected backup members.")
|
|
||||||
require(all(m.isfile() and 0 <= m.size <= LIMIT for m in members) and sum(m.size for m in members) <= LIMIT, "Invalid or oversized backup members.")
|
|
||||||
for member in members:
|
|
||||||
with archive.extractfile(member) as source, (folder / member.name).open("xb") as output:
|
|
||||||
shutil.copyfileobj(source, output)
|
|
||||||
manifest = json.loads((folder / "manifest.json").read_text())
|
|
||||||
require(manifest.get("format") == 1 and set(manifest.get("sha256", {})) == FILES - {"manifest.json"}, "Unsupported backup format.")
|
|
||||||
for name, expected in manifest["sha256"].items():
|
|
||||||
require(digest(folder / name) == expected, "Backup checksum verification failed.")
|
|
||||||
return manifest
|
|
||||||
|
|
||||||
|
|
||||||
def restore_drill(args):
|
|
||||||
backup_file = Path(args.backup).resolve()
|
|
||||||
require(backup_file.is_file(), "Backup file is missing.")
|
|
||||||
with tempfile.TemporaryDirectory(prefix="guestops-restore-", dir=ROOT) as temp:
|
|
||||||
folder = Path(temp)
|
|
||||||
run(["gpg", "--batch", "--max-output", str(LIMIT), "--output", str(folder / "bundle.tar"), "--decrypt", str(backup_file)])
|
|
||||||
require((folder / "bundle.tar").stat().st_size <= LIMIT, "Decrypted bundle exceeds the 8 GiB pilot limit.")
|
|
||||||
manifest = unpack(folder / "bundle.tar", folder)
|
|
||||||
require(image_id(args.api_image) == manifest["apiImageId"] and image_id(args.mongo_image) == manifest["mongoImageId"], "Load the exact trusted API and MongoDB images used for this backup.")
|
|
||||||
require(shutil.disk_usage(ROOT).free > 3 * manifest["inventory"]["bytes"] + 1024**3, "Insufficient restore drill space.")
|
|
||||||
keys = folder / "keys"
|
|
||||||
keys.mkdir(mode=0o700)
|
|
||||||
with tarfile.open(folder / "keys.tar.gz", "r:gz") as archive:
|
|
||||||
total = 0
|
|
||||||
for member in archive:
|
|
||||||
if member.name in (".", "./") and member.isdir():
|
|
||||||
continue
|
|
||||||
name = member.name.removeprefix("./")
|
|
||||||
total += member.size
|
|
||||||
require(member.isfile() and re.fullmatch(r"[A-Za-z0-9_-]+\.xml", name) and member.size < 1024**2 and total < 16 * 1024**2, "Invalid key archive.")
|
|
||||||
with archive.extractfile(member) as source, (keys / name).open("xb") as output:
|
|
||||||
shutil.copyfileobj(source, output)
|
|
||||||
run(["docker", "run", "--rm", "--pull", "never", "--network", "none", "--user", "0:0", "--read-only", "--mount", f"type=bind,src={keys},dst=/var/lib/guestops/keys,readonly", "-e", "Logging__LogLevel__Default=None", "-e", "BACKUP_PROBE=" + manifest["probe"], args.api_image, "--verify-backup-probe"])
|
|
||||||
cid = run(["docker", "run", "-d", "--pull", "never", "--network", "none", "--memory", "1g", "--label", "guestops.restore-drill=true", args.mongo_image, "--bind_ip", "127.0.0.1", "--setParameter", "ttlMonitorEnabled=false"]).decode().strip()
|
|
||||||
require(re.fullmatch(r"[a-f0-9]{64}", cid), "Unexpected restore container identifier.")
|
|
||||||
try:
|
|
||||||
for attempt in range(30):
|
|
||||||
try:
|
|
||||||
run(["docker", "exec", cid, "mongosh", "--quiet", "--eval", "db.adminCommand({ping:1})"], timeout=10)
|
|
||||||
break
|
|
||||||
except RuntimeError:
|
|
||||||
if attempt == 29:
|
|
||||||
raise
|
|
||||||
time.sleep(1)
|
|
||||||
with (folder / "mongo.archive.gz").open("rb") as source:
|
|
||||||
run(["docker", "exec", "-i", cid, "mongorestore", "--archive", "--gzip", "--nsInclude", "guestops.*"], input_file=source)
|
|
||||||
restored = json.loads(run(["docker", "exec", cid, "mongosh", "--quiet", "--nodb", "--eval", 'const c=new Mongo("mongodb://127.0.0.1");' + INVENTORY]))
|
|
||||||
require(restored["collections"] == manifest["inventory"]["collections"], "Restored collection counts or indexes differ.")
|
|
||||||
finally:
|
|
||||||
run(["docker", "rm", "-f", "-v", cid]) # Only the exact container created above and its anonymous volumes.
|
|
||||||
print("Restore drill passed: collection counts, indexes and actual key decryption verified in isolated containers. Production was not restored or modified.")
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
require(os.name == "posix", "Run deployment operations on Linux.")
|
|
||||||
os.umask(0o077)
|
|
||||||
parser = argparse.ArgumentParser(description=__doc__)
|
|
||||||
subs = parser.add_subparsers(dest="command", required=True)
|
|
||||||
check = subs.add_parser("preflight"); check.add_argument("--offline", action="store_true")
|
|
||||||
save = subs.add_parser("backup"); save.add_argument("--recipient", required=True); save.add_argument("--output", required=True); save.add_argument("--confirm-maintenance", action="store_true")
|
|
||||||
drill = subs.add_parser("restore-drill"); drill.add_argument("backup"); drill.add_argument("--api-image", required=True); drill.add_argument("--mongo-image", default="mongo:8.0")
|
|
||||||
args = parser.parse_args()
|
|
||||||
{"preflight": preflight, "backup": backup, "restore-drill": restore_drill}[args.command](args)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
try:
|
|
||||||
main()
|
|
||||||
except Exception as error:
|
|
||||||
# Never include subprocess output, config values or parsed guest data.
|
|
||||||
print(str(error) if isinstance(error, RuntimeError) else "Operation failed (" + type(error).__name__ + "). No sensitive details were logged.", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
@@ -0,0 +1,207 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Build a deterministic self-contained Linux GuestOps release archive."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import gzip
|
||||||
|
import io
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import tarfile
|
||||||
|
import tempfile
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
from collections.abc import Callable, Sequence
|
||||||
|
|
||||||
|
|
||||||
|
SEMVER = re.compile(r"[0-9]+\.[0-9]+\.[0-9]+")
|
||||||
|
FULL_SHA = re.compile(r"[0-9a-f]{40}")
|
||||||
|
LINUX_RUNTIME = "linux-x64"
|
||||||
|
Runner = Callable[[Sequence[str], Path], None]
|
||||||
|
|
||||||
|
|
||||||
|
def git(repository: Path, *arguments: str, binary: bool = False) -> bytes | str:
|
||||||
|
result = subprocess.run(
|
||||||
|
["git", "-C", str(repository), *arguments],
|
||||||
|
check=True,
|
||||||
|
capture_output=True,
|
||||||
|
text=not binary,
|
||||||
|
)
|
||||||
|
return result.stdout if binary else result.stdout.strip()
|
||||||
|
|
||||||
|
|
||||||
|
def committed_text(repository: Path, commit: str, path: str) -> str:
|
||||||
|
return str(git(repository, "show", f"{commit}:{path}"))
|
||||||
|
|
||||||
|
|
||||||
|
def versions(repository: Path, commit: str) -> tuple[str, str]:
|
||||||
|
props = ET.fromstring(committed_text(repository, commit, "Directory.Build.props"))
|
||||||
|
version_node = props.find(".//Version")
|
||||||
|
if version_node is None or not version_node.text:
|
||||||
|
raise ValueError("The committed Directory.Build.props has no Version element.")
|
||||||
|
dotnet_version = version_node.text.strip()
|
||||||
|
package = json.loads(committed_text(repository, commit, "web/package.json"))
|
||||||
|
return dotnet_version, str(package.get("version", ""))
|
||||||
|
|
||||||
|
|
||||||
|
def run_build(arguments: Sequence[str], working_directory: Path) -> None:
|
||||||
|
command = list(arguments)
|
||||||
|
executable = shutil.which(command[0])
|
||||||
|
if executable is None:
|
||||||
|
raise FileNotFoundError(f"Required build tool is not installed: {command[0]}")
|
||||||
|
command[0] = executable
|
||||||
|
subprocess.run(command, cwd=working_directory, check=True)
|
||||||
|
|
||||||
|
|
||||||
|
def extract_commit(repository: Path, commit: str, destination: Path) -> None:
|
||||||
|
archive = bytes(git(repository, "archive", "--format=tar", commit, binary=True))
|
||||||
|
with tarfile.open(fileobj=io.BytesIO(archive), mode="r:") as source:
|
||||||
|
source.extractall(destination, filter="data")
|
||||||
|
|
||||||
|
|
||||||
|
def add_directory(package: tarfile.TarFile, name: str) -> None:
|
||||||
|
entry = tarfile.TarInfo(name.rstrip("/") + "/")
|
||||||
|
entry.type = tarfile.DIRTYPE
|
||||||
|
entry.mode = 0o755
|
||||||
|
entry.uid = entry.gid = 0
|
||||||
|
entry.uname = entry.gname = "root"
|
||||||
|
entry.mtime = 0
|
||||||
|
package.addfile(entry)
|
||||||
|
|
||||||
|
|
||||||
|
def add_file(package: tarfile.TarFile, source: Path, name: str, executable: bool) -> None:
|
||||||
|
content = source.read_bytes()
|
||||||
|
entry = tarfile.TarInfo(name)
|
||||||
|
entry.size = len(content)
|
||||||
|
entry.mode = 0o755 if executable else 0o644
|
||||||
|
entry.uid = entry.gid = 0
|
||||||
|
entry.uname = entry.gname = "root"
|
||||||
|
entry.mtime = 0
|
||||||
|
package.addfile(entry, io.BytesIO(content))
|
||||||
|
|
||||||
|
|
||||||
|
def release_bytes(release: Path, version: str) -> bytes:
|
||||||
|
prefix = f"guestops_{version}"
|
||||||
|
tar_bytes = io.BytesIO()
|
||||||
|
with tarfile.open(fileobj=tar_bytes, mode="w", format=tarfile.PAX_FORMAT) as package:
|
||||||
|
add_directory(package, prefix)
|
||||||
|
for component in ("api", "worker"):
|
||||||
|
root = release / component
|
||||||
|
add_directory(package, f"{prefix}/{component}")
|
||||||
|
for path in sorted(root.rglob("*"), key=lambda item: item.as_posix()):
|
||||||
|
relative = path.relative_to(release).as_posix()
|
||||||
|
target = f"{prefix}/{relative}"
|
||||||
|
if path.is_dir():
|
||||||
|
add_directory(package, target)
|
||||||
|
elif path.is_file():
|
||||||
|
add_file(
|
||||||
|
package,
|
||||||
|
path,
|
||||||
|
target,
|
||||||
|
relative in {"api/GuestOps.Api", "worker/GuestOps.Worker"},
|
||||||
|
)
|
||||||
|
compressed = io.BytesIO()
|
||||||
|
with gzip.GzipFile(fileobj=compressed, mode="wb", filename="", mtime=0) as stream:
|
||||||
|
stream.write(tar_bytes.getvalue())
|
||||||
|
return compressed.getvalue()
|
||||||
|
|
||||||
|
|
||||||
|
def build_package(
|
||||||
|
repository: Path,
|
||||||
|
ref: str,
|
||||||
|
output_directory: Path,
|
||||||
|
runner: Runner = run_build,
|
||||||
|
) -> tuple[Path, dict[str, str]]:
|
||||||
|
repository = repository.resolve()
|
||||||
|
output_directory = output_directory.resolve()
|
||||||
|
if not (repository / ".git").exists():
|
||||||
|
raise ValueError("--repository must be a Git working tree.")
|
||||||
|
|
||||||
|
commit = str(git(repository, "rev-parse", "--verify", f"{ref}^{{commit}}")).lower()
|
||||||
|
if FULL_SHA.fullmatch(commit) is None:
|
||||||
|
raise ValueError("The selected ref did not resolve to a full Git commit SHA.")
|
||||||
|
|
||||||
|
dotnet_version, web_version = versions(repository, commit)
|
||||||
|
if dotnet_version != web_version:
|
||||||
|
raise ValueError(
|
||||||
|
f"Committed release versions differ: .NET={dotnet_version}, web={web_version}."
|
||||||
|
)
|
||||||
|
if SEMVER.fullmatch(dotnet_version) is None:
|
||||||
|
raise ValueError("The committed version must use MAJOR.MINOR.PATCH.")
|
||||||
|
|
||||||
|
output = output_directory / f"guestops_{dotnet_version}.tar.gz"
|
||||||
|
if output.exists():
|
||||||
|
raise ValueError("The output package already exists; published versions are not overwritten.")
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory(prefix="guestops-release-") as temporary:
|
||||||
|
root = Path(temporary)
|
||||||
|
source = root / "source"
|
||||||
|
release = root / "release"
|
||||||
|
source.mkdir()
|
||||||
|
(release / "api").mkdir(parents=True)
|
||||||
|
(release / "worker").mkdir(parents=True)
|
||||||
|
extract_commit(repository, commit, source)
|
||||||
|
|
||||||
|
runner(["npm", "ci", "--no-audit", "--no-fund"], source / "web")
|
||||||
|
runner(["npm", "run", "build"], source / "web")
|
||||||
|
common = [
|
||||||
|
"--configuration", "Release",
|
||||||
|
"--runtime", LINUX_RUNTIME,
|
||||||
|
"--self-contained", "true",
|
||||||
|
"--no-restore",
|
||||||
|
"-p:UseAppHost=true",
|
||||||
|
"-p:ContinuousIntegrationBuild=true",
|
||||||
|
"-p:Deterministic=true",
|
||||||
|
f"-p:PathMap={source}=/src",
|
||||||
|
]
|
||||||
|
runner(
|
||||||
|
["dotnet", "restore", "src/GuestOps.Api/GuestOps.Api.csproj", "--runtime", LINUX_RUNTIME],
|
||||||
|
source,
|
||||||
|
)
|
||||||
|
runner(
|
||||||
|
["dotnet", "publish", "src/GuestOps.Api/GuestOps.Api.csproj", *common, "--output", str(release / "api")],
|
||||||
|
source,
|
||||||
|
)
|
||||||
|
runner(
|
||||||
|
["dotnet", "restore", "src/GuestOps.Worker/GuestOps.Worker.csproj", "--runtime", LINUX_RUNTIME],
|
||||||
|
source,
|
||||||
|
)
|
||||||
|
runner(
|
||||||
|
["dotnet", "publish", "src/GuestOps.Worker/GuestOps.Worker.csproj", *common, "--output", str(release / "worker")],
|
||||||
|
source,
|
||||||
|
)
|
||||||
|
shutil.copytree(source / "web" / "dist", release / "api" / "wwwroot")
|
||||||
|
|
||||||
|
for required in (release / "api" / "GuestOps.Api", release / "worker" / "GuestOps.Worker"):
|
||||||
|
if not required.is_file():
|
||||||
|
raise ValueError(f"Expected native executable was not produced: {required.name}.")
|
||||||
|
if not (release / "api" / "wwwroot" / "index.html").is_file():
|
||||||
|
raise ValueError("The frontend build did not produce index.html.")
|
||||||
|
|
||||||
|
content = release_bytes(release, dotnet_version)
|
||||||
|
|
||||||
|
output_directory.mkdir(parents=True, exist_ok=True)
|
||||||
|
output.write_bytes(content)
|
||||||
|
return output, {"commit": commit, "version": dotnet_version, "runtime": LINUX_RUNTIME}
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument("--ref", required=True, help="Exact tag, branch, or full commit to package.")
|
||||||
|
parser.add_argument("--repository", type=Path, default=Path(__file__).resolve().parents[1])
|
||||||
|
parser.add_argument("--output-directory", required=True, type=Path)
|
||||||
|
args = parser.parse_args()
|
||||||
|
try:
|
||||||
|
archive, details = build_package(args.repository, args.ref, args.output_directory)
|
||||||
|
except (OSError, ValueError, ET.ParseError, json.JSONDecodeError, subprocess.SubprocessError) as error:
|
||||||
|
print(f"Release packaging failed: {error}", file=sys.stderr)
|
||||||
|
raise SystemExit(1)
|
||||||
|
print(json.dumps({"archive": str(archive), **details}, indent=2))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"approvals": {
|
||||||
|
"hotelOwner": {"approvedAt": "2026-01-01T00:00:00Z", "name": "REPLACE"},
|
||||||
|
"technicalOwner": {"approvedAt": "2026-01-01T00:00:00Z", "name": "REPLACE"}
|
||||||
|
},
|
||||||
|
"capacity": {
|
||||||
|
"hostMetricsSha256": "0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"observedConcurrency": 0,
|
||||||
|
"observedCpuHeadroomPercent": 0,
|
||||||
|
"observedErrorRate": 1,
|
||||||
|
"observedMemoryHeadroomPercent": 0,
|
||||||
|
"observedP95Ms": 0,
|
||||||
|
"reportSha256": "0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"targetConcurrency": 1,
|
||||||
|
"targetCpuHeadroomPercent": 25,
|
||||||
|
"targetErrorRate": 0,
|
||||||
|
"targetMemoryHeadroomPercent": 25,
|
||||||
|
"targetP95Ms": 0
|
||||||
|
},
|
||||||
|
"decidedAt": "2026-01-01T00:00:00Z",
|
||||||
|
"decision": "pending",
|
||||||
|
"evidence": [],
|
||||||
|
"pilot": {
|
||||||
|
"businessDaysObserved": 0,
|
||||||
|
"hotelsObserved": 0,
|
||||||
|
"recordSha256": "0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"stopConditionsObserved": 1,
|
||||||
|
"unresolvedFindings": 1
|
||||||
|
},
|
||||||
|
"releaseCommit": "0000000000000000000000000000000000000000",
|
||||||
|
"releaseRecordSha256": "0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"schemaVersion": 2,
|
||||||
|
"targetGate": "B"
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"system": "guestops-supervised-pilot",
|
||||||
|
"targetGate": "B",
|
||||||
|
"releaseCommit": "0000000000000000000000000000000000000000",
|
||||||
|
"releaseRecordSha256": "0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"environment": "https://sandbox-guestops.example.invalid",
|
||||||
|
"hotelLabel": "approved-pilot-hotel",
|
||||||
|
"hotelCount": 1,
|
||||||
|
"plannedBusinessDays": 5,
|
||||||
|
"owners": {
|
||||||
|
"hotelOwner": "REPLACE HOTEL OWNER",
|
||||||
|
"technicalOwner": "REPLACE TECHNICAL OWNER",
|
||||||
|
"rollbackDecisionMaker": "REPLACE ROLLBACK OWNER"
|
||||||
|
},
|
||||||
|
"startedOn": "2026-10-05",
|
||||||
|
"endedOn": "2026-10-09",
|
||||||
|
"pilotControls": {
|
||||||
|
"pmsWrites": "disabled",
|
||||||
|
"paymentCreation": "disabled",
|
||||||
|
"faqMode": "off",
|
||||||
|
"googleReviewedSending": "accepted"
|
||||||
|
},
|
||||||
|
"dailyReviews": [
|
||||||
|
{"date": "2026-10-05", "status": "not-run", "reviewedBy": "REPLACE", "evidence": []},
|
||||||
|
{"date": "2026-10-06", "status": "not-run", "reviewedBy": "REPLACE", "evidence": []},
|
||||||
|
{"date": "2026-10-07", "status": "not-run", "reviewedBy": "REPLACE", "evidence": []},
|
||||||
|
{"date": "2026-10-08", "status": "not-run", "reviewedBy": "REPLACE", "evidence": []},
|
||||||
|
{"date": "2026-10-09", "status": "not-run", "reviewedBy": "REPLACE", "evidence": []}
|
||||||
|
],
|
||||||
|
"stopConditions": {
|
||||||
|
"tenant-leakage": false,
|
||||||
|
"credential-exposure": false,
|
||||||
|
"data-loss": false,
|
||||||
|
"unapproved-send": false,
|
||||||
|
"duplicate-send": false,
|
||||||
|
"unreconciled-uncertain-send": false,
|
||||||
|
"failed-rollback": false,
|
||||||
|
"monitoring-loss": false
|
||||||
|
},
|
||||||
|
"findings": [],
|
||||||
|
"postPilotState": {
|
||||||
|
"pmsWrites": "disabled",
|
||||||
|
"paymentCreation": "disabled",
|
||||||
|
"faqMode": "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Validate a GuestOps supervised-pilot go/no-go record."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import datetime as dt
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
GATE_B = {
|
||||||
|
"release-package", "debian-host", "persistence", "backup-restore", "google-mailbox",
|
||||||
|
"automation", "identity-privacy", "inbox-usability", "capacity",
|
||||||
|
"incident-support", "pilot-findings",
|
||||||
|
}
|
||||||
|
GATE_C = GATE_B | {"pms-provider", "payment-provider"}
|
||||||
|
|
||||||
|
|
||||||
|
def require(condition: bool, message: str) -> None:
|
||||||
|
if not condition:
|
||||||
|
raise ValueError(message)
|
||||||
|
|
||||||
|
|
||||||
|
def timestamp(value: object, field: str) -> dt.datetime:
|
||||||
|
require(isinstance(value, str) and value.endswith("Z"), f"{field} must be a UTC timestamp ending in Z.")
|
||||||
|
try:
|
||||||
|
parsed = dt.datetime.fromisoformat(value[:-1] + "+00:00")
|
||||||
|
except ValueError as error:
|
||||||
|
raise ValueError(f"{field} is not a valid timestamp.") from error
|
||||||
|
return parsed
|
||||||
|
|
||||||
|
|
||||||
|
def validate(record: object) -> None:
|
||||||
|
require(isinstance(record, dict), "Approval record must be a JSON object.")
|
||||||
|
require(record.get("schemaVersion") == 2, "Unsupported approval schema; Gate B 0.2.2 requires schemaVersion 2.")
|
||||||
|
gate = record.get("targetGate")
|
||||||
|
require(gate in ("B", "C"), "targetGate must be B or C.")
|
||||||
|
require(record.get("decision") == "approved", "Only an explicit approved decision passes validation.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{40}", str(record.get("releaseCommit", ""))) is not None,
|
||||||
|
"releaseCommit must be a full lowercase Git SHA.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{64}", str(record.get("releaseRecordSha256", ""))) is not None,
|
||||||
|
"releaseRecordSha256 must be a SHA-256 digest.")
|
||||||
|
decided = timestamp(record.get("decidedAt"), "decidedAt")
|
||||||
|
|
||||||
|
approvals = record.get("approvals")
|
||||||
|
require(isinstance(approvals, dict) and set(approvals) == {"hotelOwner", "technicalOwner"},
|
||||||
|
"Separate hotelOwner and technicalOwner approvals are required.")
|
||||||
|
approver_names = []
|
||||||
|
for role, approval in approvals.items():
|
||||||
|
name = str(approval.get("name", "")).strip() if isinstance(approval, dict) else ""
|
||||||
|
require(2 <= len(name) <= 120 and "@" not in name,
|
||||||
|
f"{role} approval requires a named owner without an email address.")
|
||||||
|
approver_names.append(name.casefold())
|
||||||
|
require(timestamp(approval.get("approvedAt"), f"{role}.approvedAt") <= decided,
|
||||||
|
f"{role} approval cannot occur after the decision.")
|
||||||
|
require(len(set(approver_names)) == 2, "hotelOwner and technicalOwner must be different people.")
|
||||||
|
|
||||||
|
evidence = record.get("evidence")
|
||||||
|
require(isinstance(evidence, list), "evidence must be a list.")
|
||||||
|
ids = [item.get("id") for item in evidence if isinstance(item, dict)]
|
||||||
|
required = GATE_C if gate == "C" else GATE_B
|
||||||
|
require(len(ids) == len(evidence) and len(ids) == len(set(ids)) and set(ids) == required,
|
||||||
|
f"Gate {gate} requires the exact evidence set.")
|
||||||
|
for item in evidence:
|
||||||
|
item_id = item["id"]
|
||||||
|
status = item.get("status")
|
||||||
|
require(status in ("pass", "contained"), f"Evidence {item_id} must pass or have approved containment.")
|
||||||
|
references = item.get("references")
|
||||||
|
require(isinstance(references, list) and 1 <= len(references) <= 10 and all(isinstance(value, str) and 3 <= len(value) <= 200 and "@" not in value for value in references),
|
||||||
|
f"Evidence {item_id} requires safe opaque references without email addresses.")
|
||||||
|
if status == "contained":
|
||||||
|
containment = item.get("containment")
|
||||||
|
require(isinstance(containment, dict), f"Evidence {item_id} requires containment details.")
|
||||||
|
require(2 <= len(str(containment.get("owner", ""))) <= 120, f"Evidence {item_id} containment requires an owner.")
|
||||||
|
require(timestamp(containment.get("expiresAt"), f"{item_id}.containment.expiresAt") > decided,
|
||||||
|
f"Evidence {item_id} containment must expire after the decision.")
|
||||||
|
require(5 <= len(str(containment.get("rollbackTrigger", ""))) <= 300,
|
||||||
|
f"Evidence {item_id} containment requires a rollback trigger.")
|
||||||
|
|
||||||
|
capacity = record.get("capacity")
|
||||||
|
require(isinstance(capacity, dict), "Capacity thresholds and observations are required.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{64}", str(capacity.get("reportSha256", ""))) is not None,
|
||||||
|
"capacity.reportSha256 must identify the retained probe report.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{64}", str(capacity.get("hostMetricsSha256", ""))) is not None,
|
||||||
|
"capacity.hostMetricsSha256 must identify the retained host metrics.")
|
||||||
|
for observed, target in (("observedP95Ms", "targetP95Ms"), ("observedErrorRate", "targetErrorRate")):
|
||||||
|
values = (capacity.get(observed), capacity.get(target))
|
||||||
|
require(all(isinstance(value, (int, float)) and not isinstance(value, bool) for value in values)
|
||||||
|
and 0 <= capacity[observed] <= capacity[target],
|
||||||
|
f"Capacity {observed} must be within its approved {target}.")
|
||||||
|
require(capacity["targetP95Ms"] > 0, "Capacity targetP95Ms must be positive.")
|
||||||
|
require(capacity["targetErrorRate"] <= 1, "Capacity targetErrorRate must be a ratio no greater than 1.")
|
||||||
|
concurrency = (capacity.get("observedConcurrency"), capacity.get("targetConcurrency"))
|
||||||
|
require(all(isinstance(value, int) and not isinstance(value, bool) for value in concurrency)
|
||||||
|
and capacity["observedConcurrency"] >= capacity["targetConcurrency"] > 0,
|
||||||
|
"Observed concurrency must meet the approved positive target.")
|
||||||
|
for resource in ("Cpu", "Memory"):
|
||||||
|
target = capacity.get(f"target{resource}HeadroomPercent")
|
||||||
|
observed = capacity.get(f"observed{resource}HeadroomPercent")
|
||||||
|
require(all(isinstance(value, (int, float)) and not isinstance(value, bool) for value in (target, observed))
|
||||||
|
and 25 <= target <= observed <= 100,
|
||||||
|
f"Observed {resource.lower()} headroom must meet the approved target of at least 25 percent.")
|
||||||
|
|
||||||
|
pilot = record.get("pilot")
|
||||||
|
require(isinstance(pilot, dict), "A supervised pilot summary is required.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{64}", str(pilot.get("recordSha256", ""))) is not None,
|
||||||
|
"pilot.recordSha256 must identify the retained pilot run record.")
|
||||||
|
require(pilot.get("businessDaysObserved") == 5, "The pilot must cover exactly five business days.")
|
||||||
|
require(pilot.get("hotelsObserved") == 1, "The Gate B pilot must cover exactly one hotel.")
|
||||||
|
require(pilot.get("stopConditionsObserved") == 0, "A pilot with a stop condition cannot be approved.")
|
||||||
|
require(pilot.get("unresolvedFindings") == 0, "All pilot findings must be resolved or explicitly contained.")
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument("record", type=Path)
|
||||||
|
args = parser.parse_args()
|
||||||
|
validate(json.loads(args.record.read_text(encoding="utf-8")))
|
||||||
|
print("Pilot approval record is structurally complete and approved. This validates the record, not its restricted evidence.")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except (OSError, ValueError, json.JSONDecodeError) as error:
|
||||||
|
print(f"Pilot approval rejected: {error}", file=__import__("sys").stderr)
|
||||||
|
raise SystemExit(1)
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Validate a restricted five-business-day GuestOps pilot run record."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import datetime as dt
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
import re
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
|
||||||
|
STOP_CONDITIONS = {
|
||||||
|
"tenant-leakage",
|
||||||
|
"credential-exposure",
|
||||||
|
"data-loss",
|
||||||
|
"unapproved-send",
|
||||||
|
"duplicate-send",
|
||||||
|
"unreconciled-uncertain-send",
|
||||||
|
"failed-rollback",
|
||||||
|
"monitoring-loss",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def require(condition: bool, message: str) -> None:
|
||||||
|
if not condition:
|
||||||
|
raise ValueError(message)
|
||||||
|
|
||||||
|
|
||||||
|
def date_value(value: object, field: str) -> dt.date:
|
||||||
|
require(isinstance(value, str), f"{field} must be an ISO date.")
|
||||||
|
try:
|
||||||
|
return dt.date.fromisoformat(value)
|
||||||
|
except ValueError as error:
|
||||||
|
raise ValueError(f"{field} must be an ISO date.") from error
|
||||||
|
|
||||||
|
|
||||||
|
def timestamp(value: object, field: str) -> dt.datetime:
|
||||||
|
require(isinstance(value, str) and value.endswith("Z"), f"{field} must be a UTC timestamp ending in Z.")
|
||||||
|
try:
|
||||||
|
return dt.datetime.fromisoformat(value.removesuffix("Z") + "+00:00")
|
||||||
|
except ValueError as error:
|
||||||
|
raise ValueError(f"{field} is not a valid timestamp.") from error
|
||||||
|
|
||||||
|
|
||||||
|
def safe_name(value: object, field: str) -> str:
|
||||||
|
name = str(value or "").strip()
|
||||||
|
require(2 <= len(name) <= 120 and "@" not in name, f"{field} requires a name without an email address.")
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
|
def references(value: object, field: str) -> None:
|
||||||
|
require(isinstance(value, list) and 1 <= len(value) <= 10 and all(
|
||||||
|
isinstance(item, str) and 3 <= len(item) <= 200 and "@" not in item for item in value
|
||||||
|
), f"{field} requires one to ten safe opaque references without email addresses.")
|
||||||
|
|
||||||
|
|
||||||
|
def business_dates(start: dt.date, end: dt.date) -> list[dt.date]:
|
||||||
|
days = []
|
||||||
|
current = start
|
||||||
|
while current <= end:
|
||||||
|
if current.weekday() < 5:
|
||||||
|
days.append(current)
|
||||||
|
current += dt.timedelta(days=1)
|
||||||
|
return days
|
||||||
|
|
||||||
|
|
||||||
|
def validate(record: object) -> None:
|
||||||
|
require(isinstance(record, dict), "Pilot run record must be a JSON object.")
|
||||||
|
require(record.get("schemaVersion") == 1, "Unsupported pilot run schema.")
|
||||||
|
require(record.get("system") == "guestops-supervised-pilot", "Pilot run system must be guestops-supervised-pilot.")
|
||||||
|
require(record.get("targetGate") == "B", "This pilot run record is restricted to Gate B.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{40}", str(record.get("releaseCommit", ""))) is not None,
|
||||||
|
"releaseCommit must be a full lowercase Git SHA.")
|
||||||
|
require(re.fullmatch(r"[0-9a-f]{64}", str(record.get("releaseRecordSha256", ""))) is not None,
|
||||||
|
"releaseRecordSha256 must be a SHA-256 digest.")
|
||||||
|
|
||||||
|
origin = urlparse(str(record.get("environment", "")))
|
||||||
|
require(origin.scheme == "https" and origin.hostname and origin.path in ("", "/") and not origin.query
|
||||||
|
and not origin.fragment and origin.username is None and origin.password is None,
|
||||||
|
"environment must be an HTTPS origin without credentials, path, query or fragment.")
|
||||||
|
label = str(record.get("hotelLabel", "")).strip()
|
||||||
|
require(3 <= len(label) <= 80 and "@" not in label, "hotelLabel must be a non-email alias.")
|
||||||
|
require(record.get("hotelCount") == 1, "Gate B pilot must contain exactly one hotel.")
|
||||||
|
require(record.get("plannedBusinessDays") == 5, "Gate B pilot must require five business days.")
|
||||||
|
|
||||||
|
owners = record.get("owners")
|
||||||
|
require(isinstance(owners, dict) and set(owners) == {"hotelOwner", "technicalOwner", "rollbackDecisionMaker"},
|
||||||
|
"owners must contain hotelOwner, technicalOwner and rollbackDecisionMaker.")
|
||||||
|
names = {role: safe_name(value, f"owners.{role}") for role, value in owners.items()}
|
||||||
|
require(names["hotelOwner"].casefold() != names["technicalOwner"].casefold(),
|
||||||
|
"hotelOwner and technicalOwner must be different people.")
|
||||||
|
|
||||||
|
start = date_value(record.get("startedOn"), "startedOn")
|
||||||
|
end = date_value(record.get("endedOn"), "endedOn")
|
||||||
|
expected_days = business_dates(start, end)
|
||||||
|
require(len(expected_days) == 5, "Pilot window must contain exactly five business days.")
|
||||||
|
reviews = record.get("dailyReviews")
|
||||||
|
require(isinstance(reviews, list) and len(reviews) == 5, "Exactly five daily reviews are required.")
|
||||||
|
review_dates = []
|
||||||
|
for index, review in enumerate(reviews):
|
||||||
|
require(isinstance(review, dict), f"dailyReviews[{index}] must be an object.")
|
||||||
|
review_date = date_value(review.get("date"), f"dailyReviews[{index}].date")
|
||||||
|
review_dates.append(review_date)
|
||||||
|
require(review.get("status") == "pass", f"Daily review {review_date} has not passed.")
|
||||||
|
safe_name(review.get("reviewedBy"), f"dailyReviews[{index}].reviewedBy")
|
||||||
|
references(review.get("evidence"), f"dailyReviews[{index}].evidence")
|
||||||
|
require(review_dates == expected_days, "Daily reviews must cover each business day in chronological order.")
|
||||||
|
|
||||||
|
controls = record.get("pilotControls")
|
||||||
|
require(controls == {"pmsWrites": "disabled", "paymentCreation": "disabled", "faqMode": "off",
|
||||||
|
"googleReviewedSending": "accepted"},
|
||||||
|
"Pilot controls require accepted reviewed Google sending with PMS, payments and FAQ live mode disabled.")
|
||||||
|
stop_conditions = record.get("stopConditions")
|
||||||
|
require(isinstance(stop_conditions, dict) and set(stop_conditions) == STOP_CONDITIONS,
|
||||||
|
"stopConditions must contain the exact Gate B stop-condition set.")
|
||||||
|
require(all(value is False for value in stop_conditions.values()),
|
||||||
|
"A pilot with an observed stop condition cannot pass.")
|
||||||
|
|
||||||
|
findings = record.get("findings")
|
||||||
|
require(isinstance(findings, list), "findings must be a list, including an empty list when none were found.")
|
||||||
|
finding_ids = []
|
||||||
|
for finding in findings:
|
||||||
|
require(isinstance(finding, dict), "Each finding must be an object.")
|
||||||
|
finding_id = str(finding.get("id", ""))
|
||||||
|
require(re.fullmatch(r"[a-z0-9][a-z0-9-]{2,79}", finding_id) is not None, "Finding IDs must be safe opaque identifiers.")
|
||||||
|
finding_ids.append(finding_id)
|
||||||
|
severity = finding.get("severity")
|
||||||
|
disposition = finding.get("disposition")
|
||||||
|
require(severity in ("critical", "high", "medium", "low"), f"Finding {finding_id} has an invalid severity.")
|
||||||
|
require(disposition in ("resolved", "contained"), f"Finding {finding_id} must be resolved or contained.")
|
||||||
|
references(finding.get("evidence"), f"Finding {finding_id} evidence")
|
||||||
|
require(not (severity in ("critical", "high") and disposition == "contained"),
|
||||||
|
f"Finding {finding_id} is too severe for containment.")
|
||||||
|
if disposition == "contained":
|
||||||
|
containment = finding.get("containment")
|
||||||
|
require(isinstance(containment, dict), f"Finding {finding_id} requires containment details.")
|
||||||
|
safe_name(containment.get("owner"), f"Finding {finding_id} containment owner")
|
||||||
|
require(timestamp(containment.get("expiresAt"), f"Finding {finding_id}.containment.expiresAt").date() > end,
|
||||||
|
f"Finding {finding_id} containment must expire after the pilot.")
|
||||||
|
require(5 <= len(str(containment.get("rollbackTrigger", ""))) <= 300,
|
||||||
|
f"Finding {finding_id} containment requires a rollback trigger.")
|
||||||
|
require(len(finding_ids) == len(set(finding_ids)), "Finding IDs must be unique.")
|
||||||
|
|
||||||
|
require(record.get("postPilotState") == {"pmsWrites": "disabled", "paymentCreation": "disabled", "faqMode": "off"},
|
||||||
|
"Pilot must end with PMS writes, payment creation and FAQ live mode disabled.")
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument("record", type=Path)
|
||||||
|
args = parser.parse_args()
|
||||||
|
validate(json.loads(args.record.read_text(encoding="utf-8")))
|
||||||
|
print("Supervised pilot record is structurally complete: five business days passed without a stop condition. This validates the record, not its restricted evidence.")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except (OSError, ValueError, json.JSONDecodeError) as error:
|
||||||
|
print(f"Supervised pilot record rejected: {error}", file=__import__("sys").stderr)
|
||||||
|
raise SystemExit(1)
|
||||||
+3
-4
@@ -16,18 +16,17 @@ An email belongs to one hotel account. Existing active accounts cannot be reassi
|
|||||||
|
|
||||||
## Owner recovery on the Linux server
|
## Owner recovery on the Linux server
|
||||||
|
|
||||||
The server administrator must verify the owner's identity before issuing a recovery link. On the server, in the directory containing the deployed Compose file and its private environment file:
|
The server administrator must verify the owner's identity before issuing a recovery link. On the server:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
read -r -p 'Verified owner email: ' RECOVERY_EMAIL
|
read -r -p 'Verified owner email: ' RECOVERY_EMAIL
|
||||||
export RECOVERY_EMAIL
|
sudo -u cms sh -c 'set -a; . /etc/guestops/guestops.env; set +a; RECOVERY_EMAIL="$1" /srv/guestops/api/GuestOps.Api --recover-owner' sh "$RECOVERY_EMAIL"
|
||||||
docker compose run --rm --no-deps -e RECOVERY_EMAIL api --recover-owner
|
|
||||||
unset RECOVERY_EMAIL
|
unset RECOVERY_EMAIL
|
||||||
```
|
```
|
||||||
|
|
||||||
The command uses the configured database, generates a private link, prints it to the administrator's terminal and exits. Share it only with the verified owner. Do not paste it into tickets, chat logs, build logs or source control; avoid running this command in a recorded terminal. It expires in 30 minutes and can be consumed once. Running the command again invalidates the earlier link. Bootstrap remains a create-only command and cannot reset passwords.
|
The command uses the configured database, generates a private link, prints it to the administrator's terminal and exits. Share it only with the verified owner. Do not paste it into tickets, chat logs, build logs or source control; avoid running this command in a recorded terminal. It expires in 30 minutes and can be consumed once. Running the command again invalidates the earlier link. Bootstrap remains a create-only command and cannot reset passwords.
|
||||||
|
|
||||||
`PublicUrl` must be the configured HTTPS origin, normally `https://sandbox-guestops.futuresens.co.uk`. Request Host headers never determine recovery-link origins. The Development-only preview uses `http://127.0.0.1:5173`.
|
`PublicUrl` must be the configured HTTPS origin, such as `https://sandbox-guestops.futuresens.co.uk`. Request Host headers never determine recovery-link origins. The Development-only preview uses `http://127.0.0.1:5173`.
|
||||||
|
|
||||||
## Storage and session behavior
|
## Storage and session behavior
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,11 @@ The first version requires a top-level plain-text MIME message. HTML and multipa
|
|||||||
|
|
||||||
## Enable live mode after acceptance
|
## Enable live mode after acceptance
|
||||||
|
|
||||||
Keep `AUTO_REPLY_ENABLE_LIVE=false` in the deployment `.env` until the Google send/reconciliation workflow and FAQ test-mode results have been accepted. Then set it true and restart both API and worker. Gmail sending must be configured, the hotel must enable staff sending, and the mailbox must have send consent. Finally, the owner explicitly confirms test-mode acceptance and selects **Enable live replies**.
|
Keep `AutoReply__EnableLive=false` in `/etc/guestops/guestops.env` until the Google send/reconciliation workflow and FAQ test-mode results have been accepted. Then set it true and restart `guestops-api.service` and `guestops-worker.service`. Gmail sending must be configured, the hotel must enable staff sending, and the mailbox must have send consent. Finally, the owner explicitly confirms test-mode acceptance and selects **Enable live replies**.
|
||||||
|
|
||||||
|
Before test-mode acceptance, use **Batch safety evaluation** with representative synthetic cases. Each JSON case has a unique `id`, `subject`, `body`, `expectedMatch`, and optionally `expectedKnowledgeId`. The no-send evaluator accepts 1–100 cases, reads the hotel's current reviewed rules and knowledge, and reports false positives, false negatives and per-case reasons without saving a conversation or consuming a quota.
|
||||||
|
|
||||||
|
The minimum activation gate is zero false positives, zero false negatives for every supported exact question, and explicit exclusions covering additional requests, booking/payment/refund language, emergencies, accessibility or medical context, greetings/signatures, reply threads, and unsupported wording. Where `expectedMatch` is true, set `expectedKnowledgeId` so the case also proves the intended approved answer was selected. Keep the evaluated case set and result with the restricted acceptance record. Passing content cases does not replace mailbox-header, threading, quota, stop-control or delivery acceptance.
|
||||||
|
|
||||||
All modes default to Off. Every mode change creates a new activation boundary and invalidates previous queued automatic approvals. Only untouched messages received after activation and within the last 24 hours are eligible. Switching Test to Live does not send replies to previous test matches. The evaluation worker runs about every 30 seconds; the existing delivery worker handles approved outgoing messages.
|
All modes default to Off. Every mode change creates a new activation boundary and invalidates previous queued automatic approvals. Only untouched messages received after activation and within the last 24 hours are eligible. Switching Test to Live does not send replies to previous test matches. The evaluation worker runs about every 30 seconds; the existing delivery worker handles approved outgoing messages.
|
||||||
|
|
||||||
@@ -36,4 +40,4 @@ The database retains thread/recipient/quota reservations and evaluation evidence
|
|||||||
|
|
||||||
Automated tests use fake provider handlers and MongoDB; they never send live emails. They cover exact matching, exclusions, tenant boundaries, changed answers, concurrent evaluation, quotas, rule/epoch invalidation, Gmail-thread changes and uncertain delivery. Live acceptance remains pending.
|
Automated tests use fake provider handlers and MongoDB; they never send live emails. They cover exact matching, exclusions, tenant boundaries, changed answers, concurrent evaluation, quotas, rule/epoch invalidation, Gmail-thread changes and uncertain delivery. Live acceptance remains pending.
|
||||||
|
|
||||||
Test allowed questions and exclusions with your sandbox mailbox, verify duplicate prevention across restarts, inspect the actual received email, and exercise the stop control before enabling a hotel. Broad natural-language matching, multilingual questions, greetings/signature stripping, HTML/multipart equivalence and higher throughput are follow-on work requiring representative evaluation. PMS actions, payment requests and complex guest issues remain staff workflows.
|
Test allowed questions and exclusions with your sandbox mailbox, verify duplicate prevention across restarts, inspect the actual received email, and exercise the stop control before enabling a hotel. Record the owner responsible for rule changes, the operator monitoring the first live window, the rollback decision-maker, and the duration of heightened monitoring. Any false positive, unexpected recipient, duplicate, uncertain unreviewed outcome, or changed knowledge answer is a stop condition: select **Turn off**, preserve evidence, and reconcile in-flight work before considering reactivation. Broad natural-language matching, multilingual questions, greetings/signature stripping, HTML/multipart equivalence and higher throughput are follow-on work requiring representative evaluation. PMS actions, payment requests and complex guest issues remain staff workflows.
|
||||||
|
|||||||
+62
-56
@@ -1,75 +1,81 @@
|
|||||||
# Debian sandbox deployment
|
# GuestOps deployment
|
||||||
|
|
||||||
Target: `https://sandbox-guestops.futuresens.co.uk`. These are reviewable deployment instructions; creating these files does not deploy or change the server.
|
GuestOps is deployed by the central Futuresens Ansible repository. Sandbox is
|
||||||
|
`https://sandbox-guestops.futuresens.co.uk` and production is
|
||||||
|
`https://guestops.futuresens.co.uk`.
|
||||||
|
|
||||||
## 1. Prepare the host
|
## Prepare a version
|
||||||
|
|
||||||
Check the existing Nginx, Docker, MongoDB and firewall configuration before installation. Preserve existing services. The provided Compose file creates a dedicated MongoDB instance for GuestOps with no host port; if MongoDB already exists on the host, use a reviewed private connection and application-scoped user instead of starting a conflicting instance.
|
The .NET version in `Directory.Build.props` and the frontend version in
|
||||||
|
`web/package.json` must match. Test the committed revision, then package it:
|
||||||
Install Docker Engine/Compose and Nginx using their official Debian instructions. Keep SSH access unchanged. Only HTTPS/HTTP for this hostname need public access; port 8080 is loopback-only and MongoDB has no published port.
|
|
||||||
|
|
||||||
Clone the private repository using an authorized GitHub account. Place the checkout in a dedicated application directory. Copy `.env.example` to `.env`, set permissions to 600, and fill two different MongoDB passwords generated with `openssl rand -hex 32`. Use hex values so they are safe in the MongoDB URI. Store real values only on the server or in its secret-management system.
|
|
||||||
|
|
||||||
The MongoDB initialization script runs only on a new volume. Changing `.env` later does not rotate existing database users. Rotate those credentials through MongoDB administration and update application configuration together.
|
|
||||||
|
|
||||||
## 2. Load reviewed application images
|
|
||||||
|
|
||||||
CI builds API and worker images and packages them in a `guestops-linux-*` artifact. Download the successful artifact for the desired commit and transfer it to the sandbox through your normal authorized deployment process.
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
docker load -i guestops-images.tar.gz
|
dotnet run --project tests/GuestOps.Tests
|
||||||
|
python3 -m unittest discover -s tests -p "test_*.py"
|
||||||
|
cd web && npm ci && npm run build && cd ..
|
||||||
|
|
||||||
|
python3 deploy/package_release.py \
|
||||||
|
--ref FULL_COMMIT_OR_TAG \
|
||||||
|
--output-directory ../ansible/playbooks/files/guestops
|
||||||
```
|
```
|
||||||
|
|
||||||
Set `GUESTOPS_API_IMAGE=guestops-api:<commit-sha>` and `GUESTOPS_WORKER_IMAGE=guestops-worker:<commit-sha>` in `.env` using that exact build's SHA. Then run:
|
For version `0.2.2`, this creates `guestops_0.2.2.tar.gz`. The archive contains
|
||||||
|
self-contained Linux x64 API and worker applications, including the built
|
||||||
|
frontend. Published version files are immutable; change the application version
|
||||||
|
before making another archive.
|
||||||
|
|
||||||
|
## Configure Ansible
|
||||||
|
|
||||||
|
The server group needs only the application switch, version and subdomain:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
hasguestops: true
|
||||||
|
guestopsversion: "0.2.2"
|
||||||
|
guestopssubdomain: "sandbox-guestops"
|
||||||
|
```
|
||||||
|
|
||||||
|
Production uses `guestopssubdomain: "guestops"`. The native services use the
|
||||||
|
existing MongoDB service on `127.0.0.1:27017`. Google sending,
|
||||||
|
automatic live replies, AI, PMS connections, and payment connections remain
|
||||||
|
disabled until they are configured separately.
|
||||||
|
|
||||||
|
## Deploy
|
||||||
|
|
||||||
|
Deploy sandbox first:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
docker compose config --quiet
|
ansible-playbook playbooks/guestops.yml -K \
|
||||||
docker compose up -d --no-build
|
--extra-vars "thehost=sandbox"
|
||||||
curl --fail http://127.0.0.1:8080/health
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Do not run `docker compose config` without `--quiet` in shared logs: expanded configuration contains secrets. Local image builds are available with Compose for development, but CI builds avoid consuming sandbox resources.
|
After acceptance, deploy the same versioned archive to production:
|
||||||
|
|
||||||
## 3. Provision the first hotel owner
|
|
||||||
|
|
||||||
The API has an administrative bootstrap command. It creates one hotel and one owner, refuses an existing email address, and does not reset passwords. Run it with environment variables passed from a private terminal; do not put the password directly in shell history or a repository file.
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
read -r -p 'Owner email: ' BOOTSTRAP_EMAIL
|
ansible-playbook playbooks/guestops.yml -K \
|
||||||
read -r -p 'Hotel name: ' BOOTSTRAP_HOTEL
|
--extra-vars "thehost=dbserver"
|
||||||
read -r -s -p 'Owner password (14+ characters): ' BOOTSTRAP_PASSWORD
|
|
||||||
printf '\n'
|
|
||||||
export BOOTSTRAP_EMAIL BOOTSTRAP_HOTEL BOOTSTRAP_PASSWORD
|
|
||||||
docker compose run --rm --no-deps -e BOOTSTRAP_EMAIL -e BOOTSTRAP_HOTEL -e BOOTSTRAP_PASSWORD api --bootstrap
|
|
||||||
unset BOOTSTRAP_EMAIL BOOTSTRAP_HOTEL BOOTSTRAP_PASSWORD
|
|
||||||
```
|
```
|
||||||
|
|
||||||
There is no development/demo account in production. Owners can issue staff invitation and assisted recovery links through Team; see [account setup](accounts.md). Passwords must be 14–128 characters. Public self-registration is not enabled.
|
The playbook stops the existing systemd services, replaces `/srv/guestops`,
|
||||||
|
renders its environment configuration, starts the self-contained API and worker,
|
||||||
|
and manages its Nginx site. It serves HTTP before the certificate exists and
|
||||||
|
switches the site to HTTPS after Certbot has created the certificate. Port 8080
|
||||||
|
remains loopback-only and `/var/lib/guestops/keys` survives redeployment.
|
||||||
|
|
||||||
## 4. Configure HTTPS
|
On the first deployment, create the certificate after the HTTP site is available:
|
||||||
|
|
||||||
Verify the hostname's DNS resolves to this server. Obtain a valid certificate for it using your existing ACME/Certbot process. The Nginx example expects a Let's Encrypt certificate. For first issuance, configure the port-80 ACME location before enabling the port-443 block; do not point Nginx at missing certificate files.
|
```sh
|
||||||
|
sudo certbot --nginx \
|
||||||
|
-d sandbox-guestops.futuresens.co.uk \
|
||||||
|
--non-interactive \
|
||||||
|
--agree-tos \
|
||||||
|
-m dmccallum@futuresens.co.uk \
|
||||||
|
--redirect
|
||||||
|
```
|
||||||
|
|
||||||
Merge `deploy/nginx.conf` into the existing host configuration, check with `nginx -t`, then reload Nginx. Confirm HTTPS serves the login page. API cookies are always Secure outside preview mode; logging in through plain HTTP is intentionally unsupported.
|
For production, use `-d guestops.futuresens.co.uk`. Certbot obtains and renews the
|
||||||
|
certificate. Rerun the GuestOps playbook after initial certificate creation so
|
||||||
|
Ansible writes the final HTTPS proxy configuration.
|
||||||
|
|
||||||
Compose reserves the private bridge `172.30.87.0/24`, with gateway `172.30.87.1`. The API trusts the host gateway's `X-Forwarded-Proto` header so Nginx's HTTPS connections receive secure session and CSRF cookies. Check for an existing network using that range. If it conflicts, set both `GUESTOPS_SUBNET` and `GUESTOPS_GATEWAY` in `.env` to a free matching subnet and gateway. Do not replace this with unrestricted forwarded-header trust.
|
To roll back, select an older retained native `guestopsversion` (version 0.2.2 or
|
||||||
|
later) in group vars and run the same playbook. MongoDB backup, Filebeat, certificate
|
||||||
The initial rate limiter keys off the direct peer address. Behind this loopback reverse proxy it is shared across users (10 login attempts/minute), which is conservative for a pilot. Before scaling, configure explicitly trusted forwarded headers and per-account/IP rate limits; never trust arbitrary client-supplied forwarding headers.
|
renewal, and host monitoring are provided by the existing central infrastructure.
|
||||||
|
|
||||||
## 5. Configure Google
|
|
||||||
|
|
||||||
Create or select your Google Cloud project, enable Gmail API, and configure a Web application OAuth client. Register this exact redirect URI:
|
|
||||||
|
|
||||||
`https://sandbox-guestops.futuresens.co.uk/api/integrations/google/callback`
|
|
||||||
|
|
||||||
Configure `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` in the server's `.env` and recreate the API/worker services. Sign in as hotel owner, open Settings and connect a dedicated test mailbox. By default the only requested Gmail scope is `gmail.readonly`. Optional staff-approved sending adds `gmail.send` after server configuration and reconnection; see [AI drafts and reply delivery](replies.md).
|
|
||||||
|
|
||||||
OAuth requests expire after ten minutes, are bound to the signed-in user and hotel, and can be consumed once. Refresh tokens are protected with ASP.NET Data Protection. API and worker share the private persistent key volume; back it up securely with the database. Losing it prevents existing mailbox tokens and sessions from being decrypted. Filesystem protection for the key volume is required; it is separate from MongoDB and must not be publicly served or committed.
|
|
||||||
|
|
||||||
A multi-hotel production launch using Gmail restricted scopes requires planning for Google's verification/security-assessment requirements. This implementation does not bypass those requirements. See [Google restricted-scope verification](https://developers.google.com/identity/protocols/oauth2/production-readiness/restricted-scope-verification).
|
|
||||||
|
|
||||||
## 6. Acceptance and rollback
|
|
||||||
|
|
||||||
Verify separate hotels cannot read or edit each other's records; save and reload settings; restart services and confirm persistence; import test messages twice without duplicates; check the worker resumes a paginated import; confirm no mail is sent without explicit staff approval and that default-disabled sending remains blocked. Review the activity log and Google account used by the connection.
|
|
||||||
|
|
||||||
Keep reviewed image IDs and release images for rollback and backups of both MongoDB and the key volume. Do not remove named volumes to fix application errors. The initial release has no automatic schema migration that destroys data. Use the [operational preflight, encrypted backup and isolated restore drill](operations.md), and establish retention and off-server copies before importing real guest data. `/health/ready` checks database reachability; the owner's Workspace health page also reports worker heartbeat and mailbox/reply exceptions.
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# Desktop-parity acceptance
|
||||||
|
|
||||||
|
Run this supervised exercise against the exact HTTPS sandbox release using synthetic conversations and accounts. Compare the web workflow with the reviewed desktop baseline `18b983bf402ecdded6430fd40bc4d3320587595a`; this is workflow and safety parity, not a claim that the interfaces are visually identical.
|
||||||
|
|
||||||
|
Use the browser and workstation configuration intended for the pilot. Record its full browser version, operating system, viewport, scale factor and the hotel's saved IANA timezone. Keep screenshots and recordings in the restricted acceptance store because UI evidence may contain message text or account details. The operator and independent reviewer must be different people.
|
||||||
|
|
||||||
|
## Required scenarios
|
||||||
|
|
||||||
|
| Record ID | Exercise | Passing result |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `inbox-core-workflow` | Open a synthetic conversation, create and save a draft, use an approved answer, change status and reload. | The same conversation and saved state remain available, and no action sends mail. |
|
||||||
|
| `pagination-beyond-500` | Seed more than 500 tenant-scoped conversations and load successive 50-item pages while another conversation is inserted. | Every original record can be reached once without cross-hotel records, duplicates or skipped records. |
|
||||||
|
| `draft-conversation-guard` | Edit without saving, select another conversation, reject the discard prompt, then accept it. | Rejection retains the draft and selection; acceptance changes conversation and discards only the unsaved edit. |
|
||||||
|
| `draft-filter-search-guard` | Repeat the reject/accept checks while changing status filters and search text. | Rejection preserves the edit and prior view; acceptance applies the requested view change. |
|
||||||
|
| `draft-route-history-reload-guard` | With an unsaved edit, try sidebar navigation, browser Back/Forward and reload or tab close. | In-app navigation and browser history require confirmation; reload or close raises the browser's native unsaved-change warning. |
|
||||||
|
| `timezone-and-dst` | Choose a timezone different from the workstation and inspect inbox, activity, health, mailbox, automation, PMS, payment and team-link times, including values around a daylight-saving transition. | Every operational timestamp follows the saved hotel timezone and represents the same instant consistently. |
|
||||||
|
| `role-and-control-parity` | Exercise owner and staff accounts with provider writes and automation disabled. | Staff cannot access owner functions, and neither role can bypass feature, review or provider controls. |
|
||||||
|
| `desktop-layout` | Complete the workflow at the recorded desktop viewport and scale, including keyboard navigation and browser zoom checks agreed for the pilot. | Primary controls remain visible and usable without clipped dialogs, overlapping content or an inaccessible action. |
|
||||||
|
|
||||||
|
## Record and validation
|
||||||
|
|
||||||
|
Copy `deploy/desktop-acceptance.example.json` into the restricted acceptance store. Replace its release identifiers, environment, workstation details, timestamps and people. Mark each scenario `pass` only after the independent reviewer has checked its evidence. The example is intentionally invalid while scenarios are `not-run`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python3 deploy/desktop_acceptance.py /secure/acceptance/desktop-acceptance.json
|
||||||
|
```
|
||||||
|
|
||||||
|
The validator checks structure, release and baseline binding, desktop dimensions, independent review, complete passing scenarios and opaque evidence references. It cannot inspect screenshots or prove browser behavior. Retain the validated record and its checksum, then reference it from `inbox-usability` in the pilot approval record.
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# Gate B automation, identity and privacy acceptance
|
||||||
|
|
||||||
|
Run these reviews against the exact `0.2.2` candidate on the accepted HTTPS sandbox. Keep guest data, staff addresses, provider agreements, screenshots and raw reports in the restricted evidence store. Repository records contain opaque references only.
|
||||||
|
|
||||||
|
## Knowledge, AI and FAQ automation
|
||||||
|
|
||||||
|
Curate representative hotel-specific positive and negative FAQ cases. Use the bounded no-send evaluation and require zero false positives and zero false negatives. Review AI suggestions separately; escalations are valid outcomes, but no unsafe or unsupported draft may be approved. Exercise the FAQ stop control, train every pilot staff member, and name monitoring and rollback owners. Finish with FAQ mode off and PMS/payment writes disabled.
|
||||||
|
|
||||||
|
Copy `deploy/automation-acceptance.example.json`, complete the record, independently review its evidence, and run:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python3 deploy/automation_acceptance.py /secure/acceptance/automation-acceptance.json
|
||||||
|
```
|
||||||
|
|
||||||
|
## Identity, preferences and privacy
|
||||||
|
|
||||||
|
The hotel and privacy owners must approve explicit retention periods for conversations, audit history, backups and accounts. Name privacy, deletion and legal-hold owners and retain the deletion and hold procedures. Review Google processing for the mailbox pilot; either accept OpenAI processing or keep AI drafts disabled.
|
||||||
|
|
||||||
|
Exercise owner/staff boundaries, invitation and recovery lifecycle, trusted-proxy throttling, session invalidation, every owner-controlled preference, data inventory, deletion/retention handling, backup retention and audit evidence. Explicitly review the known absence of MFA, granular roles and self-service recovery; any accepted containment belongs in the final pilot decision.
|
||||||
|
|
||||||
|
Copy `deploy/identity-privacy-acceptance.example.json`, complete the record, independently review its evidence, and run:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python3 deploy/identity_privacy_acceptance.py /secure/acceptance/identity-privacy-acceptance.json
|
||||||
|
```
|
||||||
|
|
||||||
|
These validators check completeness and release binding. They do not make legal decisions, inspect provider agreements or implement deletion on behalf of the operator. Reference the retained records and validator output from `automation` and `identity-privacy` in the final pilot approval.
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
# Google mailbox acceptance
|
||||||
|
|
||||||
|
This runbook records real provider acceptance for one dedicated sandbox mailbox using synthetic messages only. It does not enable a production mailbox, FAQ automation, PMS writes or payment creation. Run it only after the exact release artifact has passed the Debian preflight and persistence drill.
|
||||||
|
|
||||||
|
Keep screenshots, Gmail message source, provider console records and request diagnostics in the restricted acceptance store. Do not commit mailbox addresses, authorization codes, refresh/access tokens, guest data, cookies, raw OAuth callbacks or raw evidence. The repository record contains only opaque evidence references.
|
||||||
|
|
||||||
|
## Preparation and stop conditions
|
||||||
|
|
||||||
|
Record the deployed GuestOps version, environment, operator, approver and maintenance window. Use two dedicated Google test accounts so the different-account rejection can be exercised without a personal account. Send only clearly synthetic messages between controlled recipients.
|
||||||
|
|
||||||
|
Start with AI drafts, staff sending, FAQ live mode, PMS writes and payment creation disabled. Confirm the OAuth redirect URI exactly matches the HTTPS sandbox. Stop immediately if a mailbox appears under the wrong hotel, a recipient differs from the review screen, an unapproved message is sent, a duplicate is observed, provider output exposes credentials, or an uncertain outcome is about to be blindly retried. Preserve evidence and follow the incident process.
|
||||||
|
|
||||||
|
## Required scenarios
|
||||||
|
|
||||||
|
| Record ID | Exercise | Passing evidence |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `oauth-readonly` | Connect sandbox mailbox A with sending disabled; inspect consent and saved health. | Only the expected read scope is granted, callback succeeds over HTTPS, mailbox identity is correct, and no credential appears in UI/log evidence. |
|
||||||
|
| `initial-import` | Send several synthetic plain-text inbox messages before and during the seven-day window, including an automated/list message. | Eligible messages import with correct sender, subject and reply identity; excluded automated mail and out-of-window mail do not appear. |
|
||||||
|
| `duplicate-import` | Restart the import pass twice and restart the worker during a paginated pass. | Each provider message appears once and the pass resumes without losing its window. |
|
||||||
|
| `same-account-reconnect` | Disconnect locally, reconnect mailbox A and inspect retained conversations/drafts. | Mailbox identity is retained, connection identity rotates, history remains, and synchronization resumes without duplicates. |
|
||||||
|
| `different-account-rejected` | Start reconnect for mailbox A but choose sandbox mailbox B. | The reconnect is rejected and mailbox A remains disconnected without B being attached to the hotel. |
|
||||||
|
| `provider-revocation` | Remove the app grant in Google's account controls, allow the worker to observe it, then reconnect A. | Health reports reconnection required without repeated provider calls; an owner reconnect restores synchronization. |
|
||||||
|
| `reviewed-send` | Enable server and hotel staff sending, reconnect for send consent, save a synthetic reply and approve its exact recipient/body. | One message appears in Gmail Sent and at the controlled recipient with the approved body, sender and stable message identity. |
|
||||||
|
| `gmail-threading` | Inspect the reviewed send in both Gmail accounts. | Gmail places it in the intended thread and message source contains the expected reply headers without CC/BCC. |
|
||||||
|
| `duplicate-approval` | Concurrently submit or repeat approval for the same imported message, then restart the worker. | Exactly one Gmail message exists; later approval/replay attempts are rejected or show the completed delivery. |
|
||||||
|
| `uncertain-send-reconciliation` | Use an approved, reviewed provider-test method to create or use an uncertain result; never induce it against uncontrolled recipients. | The item stays held, is not automatically resent, and “Verify in Gmail Sent” marks it sent only when the stable identity, sender, recipient and SENT label uniquely match. If the environment cannot safely induce uncertainty, this scenario remains unpassed. |
|
||||||
|
| `sending-stop-control` | Queue a reviewed synthetic reply, disable hotel sending before worker submission, and observe the result. | Nothing reaches Gmail and the item is rejected for staff action; re-enabling does not silently submit an old automatic approval. |
|
||||||
|
|
||||||
|
After each provider-side change, allow for the documented worker interval and capture timestamps in UTC. Treat Gmail acceptance as provider submission, not proof of final delivery; inspect the controlled recipient and any bounce separately.
|
||||||
|
|
||||||
|
## Record and approval
|
||||||
|
|
||||||
|
Copy `deploy/google-acceptance.example.json` to the restricted acceptance store outside the checkout. Replace all placeholders, change a scenario to `pass` only after reviewing its restricted evidence, and use opaque ticket or evidence IDs without email addresses. A different person should complete `acceptedBy` after checking all evidence and confirming the stop conditions did not occur.
|
||||||
|
|
||||||
|
Validate the completed record:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python3 deploy/google_acceptance.py /secure/acceptance/google-mailbox-release.json
|
||||||
|
```
|
||||||
|
|
||||||
|
The validator checks completeness, immutable release identifiers, ordered UTC timestamps, an HTTPS origin, all required passing scenarios and safe evidence references. It cannot inspect or prove the underlying evidence. Retain the record with the release and link its restricted location from the milestone tracker; do not mark milestone 12 accepted merely because the validator succeeds.
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# Incident and rollback exercise
|
||||||
|
|
||||||
|
Run this exercise on the approved sandbox release with synthetic records only. Agree detection, containment and recovery targets before starting. The operator, incident commander and independent reviewer must be different people. Keep actual guest addresses, credentials, tokens, provider payloads and raw incident evidence in the restricted acceptance store.
|
||||||
|
|
||||||
|
## Gate B scenarios
|
||||||
|
|
||||||
|
| Record ID | Exercise | Passing evidence |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `alert-and-escalate` | Introduce an approved synthetic failure and use normal monitoring and support routes. | The alert is detected, the incident commander is engaged and timestamps meet the agreed detection target. |
|
||||||
|
| `disable-worker-writes` | Use the documented controls to stop worker-driven provider writes and FAQ automation. | Pending work does not reach a provider, controls remain effective across a worker restart and staff can identify the safe state. |
|
||||||
|
| `google-uncertain-send` | Simulate an interrupted or ambiguous Gmail submission. | Staff do not resend blindly, reconcile using the stable message ID and retain the disposition. |
|
||||||
|
| `restore-readiness` | Use the isolated restore procedure and inspect provider-facing records before enabling workers. | The restored system becomes ready, older approvals remain held and external effects are reconciled. |
|
||||||
|
| `image-rollback` | Deploy the retained prior image IDs using the rollback procedure without replacing MongoDB or key volumes. | The recorded images run, readiness and read-only smoke checks pass and persistent state remains available. |
|
||||||
|
| `controlled-recovery` | Recover the approved release after containment. | Monitoring is healthy, held operations are dispositioned and the exercise ends with writes disabled and FAQ mode off. |
|
||||||
|
|
||||||
|
For Gate C, also exercise `pms-ambiguous-write` and `payment-ambiguous-create`. In both cases, lose or interrupt the synthetic provider response and prove the operation is reconciled read-only without creating a replacement request or replaying the approval.
|
||||||
|
|
||||||
|
## Record and validation
|
||||||
|
|
||||||
|
Copy `deploy/incident-exercise.example.json` into the restricted acceptance store and record the deployed GuestOps version and environment. Replace the example timestamps, people, targets and evidence references. Change a scenario to `pass` only after its evidence has been independently reviewed. The example is intentionally invalid because its scenarios are `not-run`.
|
||||||
|
|
||||||
|
For a Gate C exercise, set `targetGate` to `C` and add the PMS and payment scenario records. Validate the completed record with:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python3 deploy/incident_exercise.py /secure/acceptance/incident-exercise.json
|
||||||
|
```
|
||||||
|
|
||||||
|
The validator checks record completeness, release binding, scenario coverage, independent roles, timing targets and the safe final state. It does not inspect the referenced evidence, create an incident response capability or authorize a pilot. Retain its output and the record checksum, then reference them from `incident-support` in the pilot approval record.
|
||||||
@@ -35,3 +35,5 @@ Existing mailbox documents without a Version field remain compatible. Their conn
|
|||||||
Automated fixtures cover pagination, duplicate imports, deleted messages, invalid grants, throttling, client configuration failures, reconnect account matching, missing read scope, cross-hotel ownership, stale workers, interrupted connections and queued-reply protection. MongoDB and HTTP tests exercise persistence, legacy documents, owner-only controls and preview isolation. These tests do not contact Google.
|
Automated fixtures cover pagination, duplicate imports, deleted messages, invalid grants, throttling, client configuration failures, reconnect account matching, missing read scope, cross-hotel ownership, stale workers, interrupted connections and queued-reply protection. MongoDB and HTTP tests exercise persistence, legacy documents, owner-only controls and preview isolation. These tests do not contact Google.
|
||||||
|
|
||||||
With a dedicated test mailbox on the HTTPS sandbox, verify consent and callback configuration, initial import, disconnect, manual removal of Google access, reconnect, read-only and send scopes, retained drafts, and staff review of rejected approvals. Keep FAQ live sending and other external writes off until their separate acceptance procedures pass. Full Gmail thread aggregation, history-repair tooling and attachments remain future work.
|
With a dedicated test mailbox on the HTTPS sandbox, verify consent and callback configuration, initial import, disconnect, manual removal of Google access, reconnect, read-only and send scopes, retained drafts, and staff review of rejected approvals. Keep FAQ live sending and other external writes off until their separate acceptance procedures pass. Full Gmail thread aggregation, history-repair tooling and attachments remain future work.
|
||||||
|
|
||||||
|
Use the [Google mailbox acceptance runbook](google-acceptance.md) and its validated restricted evidence record for the complete provider exercise. Fixture and record-validation tests do not replace that live acceptance.
|
||||||
|
|||||||
+3
-3
@@ -42,11 +42,11 @@ Implemented owner-only disconnect/reconnect and import restart controls, synchro
|
|||||||
|
|
||||||
## Milestone 8: operational readiness
|
## Milestone 8: operational readiness
|
||||||
|
|
||||||
Implemented owner-only workspace health, database readiness, worker heartbeat, Linux deployment preflight, maintenance-window encrypted database/key/configuration backup and an isolated restore drill. The drill verifies collection counts, indexes and actual key decryption. Scheduling, off-server copies and production disaster cutover remain operator tasks; the Debian server rehearsal is still required. See [operations and recovery](operations.md).
|
The application provides owner-only workspace health, database readiness and worker heartbeat information. Filebeat, MongoDB backup, host monitoring and disaster recovery are owned by the existing central infrastructure rather than duplicated inside GuestOps. GuestOps runs as native systemd services.
|
||||||
|
|
||||||
## Remaining milestones
|
## Remaining milestones
|
||||||
|
|
||||||
1. Run dedicated Google test-mailbox acceptance, add full thread aggregation and history repair, and rehearse server backup/restore before the first hotel pilot.
|
1. Run dedicated Google test-mailbox acceptance, add full thread aggregation and history repair, and confirm the central server backup/restore process before the first hotel pilot.
|
||||||
2. Add verified transactional email for invitations and recovery notifications, MFA, granular roles and user preferences.
|
2. Add verified transactional email for invitations and recovery notifications, MFA, granular roles and user preferences.
|
||||||
3. Run a representative live AI draft evaluation, improve retrieval and evidence presentation, and approve the selected provider data-processing arrangements.
|
3. Run a representative live AI draft evaluation, improve retrieval and evidence presentation, and approve the selected provider data-processing arrangements.
|
||||||
4. Extend the implemented durable reply queue with operator recovery tooling and broaden the controlled FAQ rules only after live acceptance. Preserve the rule that uncertain sends are never blindly replayed.
|
4. Extend the implemented durable reply queue with operator recovery tooling and broaden the controlled FAQ rules only after live acceptance. Preserve the rule that uncertain sends are never blindly replayed.
|
||||||
@@ -56,7 +56,7 @@ Windows DPAPI settings must not be copied to Linux as usable credentials. Re-ent
|
|||||||
|
|
||||||
## Capacity and operations
|
## Capacity and operations
|
||||||
|
|
||||||
Target supplied by the owner: Debian 12, 4 CPU cores, 7.6 GiB RAM, 18 GiB free disk; MongoDB on the same machine. Compose includes conservative starting memory limits and capped logs, not a capacity guarantee. Keep database/key backups off-server and do not import entire mailboxes by default. Establish retention and restore testing before real guest data is used.
|
Target supplied by the owner: Debian 12, 4 CPU cores, 7.6 GiB RAM, 18 GiB free disk; MongoDB on the same machine. The native API and worker write to the systemd journal; their resource use must be confirmed during sandbox acceptance. Keep database/key backups off-server and do not import entire mailboxes by default. Establish retention and restore testing before real guest data is used.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
# Operations and recovery
|
|
||||||
|
|
||||||
The owner-only **Workspace health** page reports database reachability, the worker's last heartbeat, mailbox recovery counts and reply exceptions. A heartbeat older than three minutes is marked stale. It proves that the worker process recently reached MongoDB, not that every provider or job succeeded. Reply totals cover at most the latest 500 conversations in this hotel. The page does not verify backups. `/health/ready` returns only readiness status and HTTP 503 when the database cannot be reached.
|
|
||||||
|
|
||||||
## Deployment preflight
|
|
||||||
|
|
||||||
Run from the dedicated GuestOps checkout on Linux with Python 3.11 or later, Docker with Compose, and GnuPG installed. The tool supports the supplied three-service Compose deployment and the `guestops` database only. Docker access is administrator-equivalent; use the designated server operator account. Load the reviewed API, worker and MongoDB images first, configure `.env` with mode 600, and follow [deployment](deployment.md).
|
|
||||||
|
|
||||||
```sh
|
|
||||||
python3 deploy/ops.py preflight --offline
|
|
||||||
# After Nginx, DNS, TLS and services are running:
|
|
||||||
python3 deploy/ops.py preflight
|
|
||||||
```
|
|
||||||
|
|
||||||
Preflight checks production settings, shared persistent keys, unpublished MongoDB/worker ports, a loopback API port, required images and mounts, private secret files, and at least 8 GiB free disk. The online check also verifies the configured HTTPS readiness URL. This is not a firewall, capacity or provider acceptance test. Allow additional disk space for the database, images and temporary backup/restore files; the supplied server initially had 18 GiB free.
|
|
||||||
|
|
||||||
Configured provider files must be readable by the API container's `app` user while inaccessible to other users. Set their ownership to that image's application UID and mode 600, and run the backup as an authorized operator able to read them (for example root with its designated public GPG keyring). Keep their parent directory private. Empty shipped example files contain no credentials and do not need this ownership change. Check the UID in the reviewed image rather than assuming it matches your host login.
|
|
||||||
|
|
||||||
## Encrypted backup
|
|
||||||
|
|
||||||
Keep the recovery private key on an administrator-controlled recovery machine, with a securely stored passphrase and a second protected recovery copy. Import only its public key on the server and verify its full 40-character fingerprint through a trusted channel. The tool selects that exact fingerprint; it does not establish who owns the key. Do not put private keys, decrypted backups or provider secrets in GitHub.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
gpg --import /secure/path/recovery-public.asc
|
|
||||||
gpg --fingerprint
|
|
||||||
install -d -m 700 "$HOME/guestops-backups"
|
|
||||||
read -r -p 'Verified recovery key fingerprint: ' BACKUP_RECIPIENT
|
|
||||||
python3 deploy/ops.py backup --recipient "$BACKUP_RECIPIENT" \
|
|
||||||
--output "$HOME/guestops-backups/guestops-$(date -u +%Y%m%dT%H%M%SZ).tar.gpg" \
|
|
||||||
--confirm-maintenance
|
|
||||||
unset BACKUP_RECIPIENT
|
|
||||||
```
|
|
||||||
|
|
||||||
This command causes a maintenance interruption. It stops the API and worker, temporarily pauses MongoDB's TTL expiry monitor, dumps MongoDB, and saves the shared Data Protection keys and deployed configuration. The configuration includes credentials and provider files, so the entire bundle is encrypted. Services and the previous TTL setting are restored in a `finally` block before encryption finishes. A successful backup message does not prove that restarted services are healthy; run the online preflight afterwards.
|
|
||||||
|
|
||||||
No other application or administrator may write to this database during the snapshot. Standalone MongoDB dumps need coordinated writes for consistency; see the [MongoDB backup guidance](https://www.mongodb.com/docs/v8.0/tutorial/backup-and-restore-tools/). The tool is intentionally limited to the dedicated stack. It requires the hexadecimal MongoDB root password generated in the deployment guide.
|
|
||||||
|
|
||||||
Copy the encrypted file off-server to restricted storage after every successful backup. Retain the exact API, worker and MongoDB images with the release: an image tag alone can change, and the drill requires matching image IDs. Agree the backup schedule, retention and tolerated data loss before a hotel pilot. Scheduling, off-server transfer, deletion and alerting are operator responsibilities in this milestone; none is silently installed.
|
|
||||||
|
|
||||||
Temporary plaintext files are held in private directories and removed on normal completion or exceptions. Process termination or power loss can leave temporary data, stopped services or TTL expiry disabled. After an interrupted run, inspect the dedicated project and remove only its identified abandoned temporary directory after securing any recovery material. Restore the recorded TTL setting (normally true) and restart the services:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
docker compose exec -T mongo mongosh --quiet --nodb --eval 'const c=new Mongo("mongodb://127.0.0.1"); c.getDB("admin").auth(process.env.MONGO_INITDB_ROOT_USERNAME,process.env.MONGO_INITDB_ROOT_PASSWORD); const r=c.getDB("admin").runCommand({setParameter:1,ttlMonitorEnabled:true}); if(!r.ok)quit(1);'
|
|
||||||
docker compose start api worker
|
|
||||||
python3 deploy/ops.py preflight
|
|
||||||
```
|
|
||||||
|
|
||||||
Use the previous value instead of true if TTL expiry was deliberately disabled beforehand. Do not remove production volumes to recover from a failed backup.
|
|
||||||
|
|
||||||
## Isolated restore drill
|
|
||||||
|
|
||||||
Use a trusted encrypted backup and the recovery key on a Linux recovery machine. Unlock the key through the local GPG agent before running the batch command; never pass its passphrase on the command line. Load the exact reviewed images from the backed-up release first.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
python3 deploy/ops.py restore-drill /secure/path/guestops-backup.tar.gpg \
|
|
||||||
--api-image guestops-api:REVIEWED_RELEASE \
|
|
||||||
--mongo-image mongo:8.0
|
|
||||||
```
|
|
||||||
|
|
||||||
The drill decrypts into a private temporary directory, checks the four expected files and their hashes, rejects unsafe archive entries, and verifies that the restored keys decrypt a protected test value. It then restores MongoDB into a newly created container with no external network or published ports and compares every restored collection's count and indexes. TTL expiry is disabled in this disposable database so expired token records do not disappear during comparison. The exact temporary container and its volumes are removed afterwards. No worker or production application is started.
|
|
||||||
|
|
||||||
The decrypted bundle is capped at 8 GiB for this pilot tool. Leave room for the encrypted file, decrypted archive, extracted files and restored database. GPG's [output limit](https://www.gnupg.org/documentation/manuals/gnupg/GPG-Input-and-Output.html) bounds decrypted output; checksums detect corruption, not the identity of the backup creator. Use backups from the trusted operator only. A drill checks counts, indexes and key decryption, not every document's business meaning or live provider connectivity.
|
|
||||||
|
|
||||||
## Actual disaster recovery
|
|
||||||
|
|
||||||
This milestone implements a rehearsal, not an automatic production restore or cutover command. Before real guest data is accepted, rehearse a separate recovery deployment and document its precise image IDs, volume names, secret locations and operator responsibilities.
|
|
||||||
|
|
||||||
Restore into new isolated MongoDB and key volumes; preserve the damaged original for investigation. Reconstruct reviewed configuration from the encrypted bundle without copying old Docker container IDs or blindly executing archived configuration. Restore the `guestops` database with the compatible MongoDB tools and restore the matching key files with the application's required ownership. Check hotel/account records and saved settings before exposing the recovered API. Keep the worker stopped, provider writes disabled and external network access restricted throughout this process.
|
|
||||||
|
|
||||||
**A restored database can predate emails, invoices and PMS changes that providers already completed.** Review pending, sending and uncertain records against provider evidence before enabling any worker, including automatic FAQ rules. Do not replay an older approval merely because the restored record says it is pending. Reconcile external effects, validate account sessions and mailbox authorization, and explicitly approve the cutover only after these checks. Rotate credentials if compromise prompted the recovery. Keep the old deployment stopped when enabling the replacement.
|
|
||||||
|
|
||||||
CI exercises a synthetic encrypted backup and isolated restore drill, including actual key decryption and database comparison. A successful CI drill is separate from the required rehearsal on the Debian server with its actual deployment configuration.
|
|
||||||
|
|
||||||
+2
-2
@@ -23,7 +23,7 @@ Copy `deploy/payments.example.json` to a private `payments.local.json` outside t
|
|||||||
|
|
||||||
Use the internal 32-character hotel ID shown on the Payments page. `MerchantAccount` is an administrator-maintained identity binding: verify it against the merchant account behind the key. Do not reuse the same identity for a different merchant. The API accepts only `https://sandbox.nmi.com` and `https://secure.nmi.com`; confirm the correct environment and key with NMI.
|
Use the internal 32-character hotel ID shown on the Payments page. `MerchantAccount` is an administrator-maintained identity binding: verify it against the merchant account behind the key. Do not reuse the same identity for a different merchant. The API accepts only `https://sandbox.nmi.com` and `https://secure.nmi.com`; confirm the correct environment and key with NMI.
|
||||||
|
|
||||||
Set `PAYMENTS_CONFIG_FILE_HOST` in the deployment `.env` to the absolute private file path. Compose mounts it read-only in the API only. Restrict file permissions to the administrator and the container user/group that needs read access. Determine the image's user with `docker run --rm --entrypoint id YOUR_API_IMAGE -u` before assigning permissions. Restart the API after changes. The default empty example disables the integration. Do not commit private configuration or put keys in the browser.
|
Store the private file as `/etc/guestops/payments.json`, owned by `root:cms` with mode `0640`, and set `Payments__ConfigFile=/etc/guestops/payments.json` in `/etc/guestops/guestops.env`. Only the native API service reads it. Restart `guestops-api.service` after changes. Leaving the setting unset disables the integration. Do not commit private configuration or put keys in the browser or release archive.
|
||||||
|
|
||||||
After sandbox acceptance, enable `CreatesEnabled` on the server and **Allow owner-approved payment invoices** in the hotel's Payments page. Both controls are required. Turning off creation leaves read-only reconciliation available. Key rotation preserves reconciliation for the same merchant binding; pending approvals require the original credential revision and must be replaced after rotation. Changing the merchant identity blocks reconciliation until the original binding is restored.
|
After sandbox acceptance, enable `CreatesEnabled` on the server and **Allow owner-approved payment invoices** in the hotel's Payments page. Both controls are required. Turning off creation leaves read-only reconciliation available. Key rotation preserves reconciliation for the same merchant binding; pending approvals require the original credential revision and must be replaced after rotation. Changing the merchant identity blocks reconciliation until the original binding is restored.
|
||||||
|
|
||||||
@@ -46,6 +46,6 @@ Only unsubmitted proposals can be cancelled in GuestOps. Invoice closure, refund
|
|||||||
|
|
||||||
## Acceptance before live use
|
## Acceptance before live use
|
||||||
|
|
||||||
Automated tests use an in-process fake HTTP handler and never contact NMI. They cover tenant isolation, amount/currency/identity mismatches, partial status, concurrent approvals, lost create responses, pagination and merchant changes. CI checks the production configuration mount and disabled defaults.
|
Automated tests use an in-process fake HTTP handler and never contact NMI. They cover tenant isolation, amount/currency/identity mismatches, partial status, concurrent approvals, lost create responses, pagination and merchant changes. Run the production-configuration and disabled-default checks before packaging and again during the Ansible deployment verification.
|
||||||
|
|
||||||
Use a dedicated sandbox merchant and recipient to validate authentication, supported currency, exact request/response fields, preservation of `order_details.order_id`, customer invoice email and hosted checkout, partial/full payments and interrupted-request recovery. Live acceptance remains pending. Planet, direct payment links in GuestOps replies, automatic booking after payment, automated expiry/closure and background polling are follow-on work.
|
Use a dedicated sandbox merchant and recipient to validate authentication, supported currency, exact request/response fields, preservation of `order_details.order_id`, customer invoice email and hosted checkout, partial/full payments and interrupted-request recovery. Live acceptance remains pending. Planet, direct payment links in GuestOps replies, automatic booking after payment, automated expiry/closure and background polling are follow-on work.
|
||||||
|
|||||||
+2
-2
@@ -29,9 +29,9 @@ Copy `deploy/pms.example.json` to a private `pms.local.json` outside your checko
|
|||||||
|
|
||||||
Use the client-credentials grant and property permissions supplied for your OHIP environment. Confirm the note type and notification-location codes with the property. The gateway must be an HTTPS origin, without a path. There is no shared fallback configuration between hotels.
|
Use the client-credentials grant and property permissions supplied for your OHIP environment. Confirm the note type and notification-location codes with the property. The gateway must be an HTTPS origin, without a path. There is no shared fallback configuration between hotels.
|
||||||
|
|
||||||
Set `PMS_CONFIG_FILE_HOST` in the deployment `.env` to the absolute private file path. Compose mounts it read-only into the API; the worker does not receive these credentials. Restrict host permissions to the administrator and the API container's user/group, while allowing that user to read the file. Obtain the image's user ID with `docker run --rm --entrypoint id YOUR_API_IMAGE -u` before assigning permissions. Never put credentials in the browser, repository or an image. Restart the API after configuration changes; this file is not hot-reloaded.
|
Store the private file as `/etc/guestops/pms.json`, owned by `root:cms` with mode `0640`, and set `Pms__ConfigFile=/etc/guestops/pms.json` in `/etc/guestops/guestops.env`. Only the native API service needs these credentials. Never put them in the browser, repository or release archive. Restart `guestops-api.service` after configuration changes; this file is not hot-reloaded.
|
||||||
|
|
||||||
The default deployment mounts an empty example and makes no OHIP calls. Begin with sandbox credentials and `WritesEnabled: false`. Lookups can be tested without enabling writes. After sandbox acceptance, server write enablement and the hotel's owner-controlled MongoDB setting must both be enabled. Every operation still needs individual owner approval.
|
The default deployment does not set a PMS configuration file and makes no OHIP calls. Begin with sandbox credentials and `WritesEnabled: false`. Lookups can be tested without enabling writes. After sandbox acceptance, server write enablement and the hotel's owner-controlled MongoDB setting must both be enabled. Every operation still needs individual owner approval.
|
||||||
|
|
||||||
## Review and recovery
|
## Review and recovery
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -5,8 +5,8 @@ This milestone adds AI suggestions and a persistent send queue. It does not enab
|
|||||||
## Enable on the sandbox
|
## Enable on the sandbox
|
||||||
|
|
||||||
1. Deploy the reviewed images using the deployment guide. Existing hotel records default to AI off and sending off.
|
1. Deploy the reviewed images using the deployment guide. Existing hotel records default to AI off and sending off.
|
||||||
2. Set `AI_API_KEY` and `AI_MODEL` in the server's private `.env`. Choose a model available to your OpenAI project that supports the Responses API and strict JSON-schema output. No model is silently selected and no key is stored in frontend code or MongoDB. Only the API container receives the AI key.
|
2. Set `Ai__ApiKey` and `Ai__Model` in the server's private `/etc/guestops/guestops.env`. Choose a model available to your OpenAI project that supports the Responses API and strict JSON-schema output. No model is silently selected and no key is stored in frontend code or MongoDB. Only the API uses the AI key.
|
||||||
3. Recreate API/worker containers. In hotel Settings, the owner can enable AI drafts. The opt-in explains that staff-requested generation sends the message subject/body and selected approved hotel answers to OpenAI. Requests use `store: false`; this does not replace reviewing the provider's data-processing and retention arrangements.
|
3. Restart `guestops-api.service`. In hotel Settings, the owner can enable AI drafts. The opt-in explains that staff-requested generation sends the message subject/body and selected approved hotel answers to OpenAI. Requests use `store: false`; this does not replace reviewing the provider's data-processing and retention arrangements.
|
||||||
4. For sending, set `GOOGLE_ENABLE_SENDING=true`, recreate API/worker, and reconnect Google. The OAuth request then includes `gmail.readonly` and `gmail.send`. An existing read-only refresh token is not assumed to have send permission; the returned grant must explicitly include `gmail.send`.
|
4. For sending, set `GOOGLE_ENABLE_SENDING=true`, recreate API/worker, and reconnect Google. The OAuth request then includes `gmail.readonly` and `gmail.send`. An existing read-only refresh token is not assumed to have send permission; the returned grant must explicitly include `gmail.send`.
|
||||||
5. Enable staff-approved sending in that hotel's Settings. Use a dedicated test mailbox and synthetic guest messages for live acceptance tests before enabling a real hotel mailbox.
|
5. Enable staff-approved sending in that hotel's Settings. Use a dedicated test mailbox and synthetic guest messages for live acceptance tests before enabling a real hotel mailbox.
|
||||||
|
|
||||||
@@ -34,6 +34,6 @@ Current limitations: messages imported before reply headers were stored must be
|
|||||||
|
|
||||||
## Verification
|
## Verification
|
||||||
|
|
||||||
The test suite covers competing workers, send identity/thread headers, invalid recipients, header injection, uncertain outcomes, restart recovery, pre-send token failure, disabling hotel sending, cross-hotel access, Gmail reconciliation mismatches, AI source isolation, invalid citations, escalations and incomplete responses. CI also runs production container login/restart-persistence smoke checks. Live acceptance must additionally verify Google consent, actual threading, grant revocation, a representative AI draft evaluation set and provider error behaviour with the configured accounts.
|
The test suite covers competing workers, send identity/thread headers, invalid recipients, header injection, uncertain outcomes, restart recovery, pre-send token failure, disabling hotel sending, cross-hotel access, Gmail reconciliation mismatches, AI source isolation, invalid citations, escalations and incomplete responses. Run the native-service login and restart-persistence smoke checks before packaging and during Ansible deployment verification. Live acceptance must additionally verify Google consent, actual threading, grant revocation, a representative AI draft evaluation set and provider error behaviour with the configured accounts.
|
||||||
|
|
||||||
Implementation references: [OpenAI Structured Outputs](https://developers.openai.com/api/docs/guides/structured-outputs), [Gmail sending](https://developers.google.com/workspace/gmail/api/guides/sending), [Gmail threads](https://developers.google.com/workspace/gmail/api/guides/threads).
|
Implementation references: [OpenAI Structured Outputs](https://developers.openai.com/api/docs/guides/structured-outputs), [Gmail sending](https://developers.google.com/workspace/gmail/api/guides/sending), [Gmail threads](https://developers.google.com/workspace/gmail/api/guides/threads).
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ public sealed record AutoRuleInput(string Question,string KnowledgeId,bool Enabl
|
|||||||
public sealed record AutoModeInput(string Mode,long Version,bool AcceptanceConfirmed);
|
public sealed record AutoModeInput(string Mode,long Version,bool AcceptanceConfirmed);
|
||||||
public sealed record AutoTestInput(string Subject,string Body);
|
public sealed record AutoTestInput(string Subject,string Body);
|
||||||
public sealed record AutoDecision(bool Matches,string Reason,string RuleId="",string KnowledgeId="",string Body="");
|
public sealed record AutoDecision(bool Matches,string Reason,string RuleId="",string KnowledgeId="",string Body="");
|
||||||
|
public sealed record AutoEvaluationCase(string Id,string Subject,string Body,bool ExpectedMatch,string ExpectedKnowledgeId="");
|
||||||
|
public sealed record AutoEvaluationInput(AutoEvaluationCase[] Cases);
|
||||||
|
public sealed record AutoEvaluationResult(string Id,bool Passed,bool ExpectedMatch,bool ActualMatch,string ExpectedKnowledgeId,string ActualKnowledgeId,string Reason);
|
||||||
public static class FaqMatcher
|
public static class FaqMatcher
|
||||||
{
|
{
|
||||||
public static readonly string[] Questions=["What time is check in?","What time is check out?","Where can I park?","Is parking available?","What time is breakfast?","Do you have WiFi?","What is your address?"];
|
public static readonly string[] Questions=["What time is check in?","What time is check out?","Where can I park?","Is parking available?","What time is breakfast?","Do you have WiFi?","What is your address?"];
|
||||||
@@ -52,6 +55,16 @@ public sealed class AutoReplyWork(IStore store,IConfiguration config)
|
|||||||
{
|
{
|
||||||
public bool LiveConfigured=>config.GetValue<bool>("AutoReply:EnableLive");
|
public bool LiveConfigured=>config.GetValue<bool>("AutoReply:EnableLive");
|
||||||
public async Task<AutoDecision> Test(string hotel,string subject,string body)=>FaqMatcher.Evaluate(new Conversation{HotelId=hotel,Subject=subject,Body=body},await store.List<AutoReplyRule>(hotel),await store.List<KnowledgeEntry>(hotel));
|
public async Task<AutoDecision> Test(string hotel,string subject,string body)=>FaqMatcher.Evaluate(new Conversation{HotelId=hotel,Subject=subject,Body=body},await store.List<AutoReplyRule>(hotel),await store.List<KnowledgeEntry>(hotel));
|
||||||
|
public async Task<AutoEvaluationResult[]> Evaluate(string hotel,IEnumerable<AutoEvaluationCase> cases)
|
||||||
|
{
|
||||||
|
var rules=await store.List<AutoReplyRule>(hotel);var knowledge=await store.List<KnowledgeEntry>(hotel);
|
||||||
|
return cases.Select(item=>
|
||||||
|
{
|
||||||
|
var decision=FaqMatcher.Evaluate(new Conversation{HotelId=hotel,Subject=item.Subject,Body=item.Body},rules,knowledge);
|
||||||
|
var passed=decision.Matches==item.ExpectedMatch&&(!item.ExpectedMatch||item.ExpectedKnowledgeId.Length==0||decision.KnowledgeId==item.ExpectedKnowledgeId);
|
||||||
|
return new AutoEvaluationResult(item.Id,passed,item.ExpectedMatch,decision.Matches,item.ExpectedKnowledgeId,decision.KnowledgeId,decision.Reason);
|
||||||
|
}).ToArray();
|
||||||
|
}
|
||||||
public async Task Process(Conversation message)
|
public async Task Process(Conversation message)
|
||||||
{
|
{
|
||||||
var hotel=await store.Get<Hotel>(message.HotelId,message.HotelId);
|
var hotel=await store.Get<Hotel>(message.HotelId,message.HotelId);
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ public static class AutoReplyEndpoints
|
|||||||
group.MapPost("/test",async(AutoTestInput input,HttpContext c,AutoReplyWork work)=>{
|
group.MapPost("/test",async(AutoTestInput input,HttpContext c,AutoReplyWork work)=>{
|
||||||
if(!Input.Text(input.Subject,0,200)||!Input.Text(input.Body,1,2000))return Results.BadRequest();return Results.Ok(await work.Test(Session.Hotel(c),input.Subject,input.Body));
|
if(!Input.Text(input.Subject,0,200)||!Input.Text(input.Body,1,2000))return Results.BadRequest();return Results.Ok(await work.Test(Session.Hotel(c),input.Subject,input.Body));
|
||||||
}).RequireAuthorization("Owner");
|
}).RequireAuthorization("Owner");
|
||||||
|
group.MapPost("/evaluate",async(AutoEvaluationInput input,HttpContext c,AutoReplyWork work)=>{
|
||||||
|
if(input.Cases is not {Length:>=1 and <=100} cases||cases.Select(x=>x.Id).Distinct(StringComparer.Ordinal).Count()!=cases.Length||cases.Any(x=>!Input.Text(x.Id,1,80)||!Input.Text(x.Subject,0,200)||!Input.Text(x.Body,1,2000)||x.ExpectedKnowledgeId.Length>80))return Results.BadRequest();
|
||||||
|
var results=await work.Evaluate(Session.Hotel(c),cases);return Results.Ok(new{total=results.Length,passed=results.Count(x=>x.Passed),falsePositives=results.Count(x=>!x.ExpectedMatch&&x.ActualMatch),falseNegatives=results.Count(x=>x.ExpectedMatch&&!x.ActualMatch),results});
|
||||||
|
}).RequireAuthorization("Owner");
|
||||||
group.MapPut("/rules/{question:int}",async(int question,AutoRuleInput input,HttpContext c,IStore store)=>{
|
group.MapPut("/rules/{question:int}",async(int question,AutoRuleInput input,HttpContext c,IStore store)=>{
|
||||||
if(question<0||question>=FaqMatcher.Questions.Length||input.Question!=FaqMatcher.Questions[question])return Results.BadRequest();
|
if(question<0||question>=FaqMatcher.Questions.Length||input.Question!=FaqMatcher.Questions[question])return Results.BadRequest();
|
||||||
var hotel=Session.Hotel(c);var key=Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(hotel+":"+question))).ToLowerInvariant()[..32];
|
var hotel=Session.Hotel(c);var key=Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(hotel+":"+question))).ToLowerInvariant()[..32];
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using System.Text;
|
||||||
|
namespace GuestOps.Web;
|
||||||
|
|
||||||
|
public sealed record ConversationPage(IReadOnlyList<Conversation> Items,string? NextCursor);
|
||||||
|
public static class ConversationPaging
|
||||||
|
{
|
||||||
|
public static string Encode(Conversation item)=>Convert.ToBase64String(Encoding.UTF8.GetBytes(item.ReceivedAt.Ticks+"|"+item.Id)).TrimEnd('=').Replace('+','-').Replace('/','_');
|
||||||
|
public static bool TryDecode(string? value,out DateTime at,out string id)
|
||||||
|
{
|
||||||
|
at=default;id="";if(string.IsNullOrEmpty(value))return true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(value.Length>160)return false;var raw=value.Replace('-','+').Replace('_','/');raw=raw.PadRight((raw.Length+3)/4*4,'=');
|
||||||
|
var parts=Encoding.UTF8.GetString(Convert.FromBase64String(raw)).Split('|');
|
||||||
|
return parts.Length==2&&long.TryParse(parts[0],out var ticks)&&ticks>=DateTime.MinValue.Ticks&&ticks<=DateTime.MaxValue.Ticks&&System.Text.RegularExpressions.Regex.IsMatch(parts[1],"^[a-f0-9]{32}$")&&(at=new DateTime(ticks,DateTimeKind.Utc))!=default&&(id=parts[1]).Length>0;
|
||||||
|
}
|
||||||
|
catch{return false;}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,8 +22,8 @@ public static class Operations
|
|||||||
});
|
});
|
||||||
api.MapGet("/operations",async(HttpContext c,IStore store)=>
|
api.MapGet("/operations",async(HttpContext c,IStore store)=>
|
||||||
{
|
{
|
||||||
var id=Session.Hotel(c);var boxes=await store.List<Mailbox>(id);var messages=await store.List<Conversation>(id);var seen=await store.WorkerLastSeen();
|
var id=Session.Hotel(c);var hotel=await store.Get<Hotel>(id,id);var boxes=await store.List<Mailbox>(id);var messages=await store.List<Conversation>(id);var seen=await store.WorkerLastSeen();
|
||||||
return Results.Ok(new{checkedAt=DateTime.UtcNow,preview,database="Reachable",worker=new{lastSeenAt=seen,state=preview?"Preview":seen==null?"NotSeen":seen<DateTime.UtcNow.AddMinutes(-3)?"Stale":"Reporting"},mailboxes=new{total=boxes.Count,connected=boxes.Count(x=>x.Status=="Connected"),attention=boxes.Count(x=>x.Status!="Connected"||x.SyncError.Length>0)},replies=new{sampleSize=messages.Count,sampleLimit=500,pending=messages.Count(x=>x.Delivery?.State is "Pending" or "Sending"),uncertain=messages.Count(x=>x.Delivery?.State=="NeedsReview"),rejected=messages.Count(x=>x.Delivery?.State=="Rejected")}});
|
return Results.Ok(new{checkedAt=DateTime.UtcNow,timeZone=hotel?.Timezone??"UTC",preview,database="Reachable",worker=new{lastSeenAt=seen,state=preview?"Preview":seen==null?"NotSeen":seen<DateTime.UtcNow.AddMinutes(-3)?"Stale":"Reporting"},mailboxes=new{total=boxes.Count,connected=boxes.Count(x=>x.Status=="Connected"),attention=boxes.Count(x=>x.Status!="Connected"||x.SyncError.Length>0)},replies=new{sampleSize=messages.Count,sampleLimit=500,pending=messages.Count(x=>x.Delivery?.State is "Pending" or "Sending"),uncertain=messages.Count(x=>x.Delivery?.State=="NeedsReview"),rejected=messages.Count(x=>x.Delivery?.State=="Rejected")}});
|
||||||
}).RequireAuthorization("Owner");
|
}).RequireAuthorization("Owner");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,9 +55,9 @@ builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationSc
|
|||||||
builder.Services.AddAuthorization(o => o.AddPolicy("Owner", p => p.RequireRole("Owner")));
|
builder.Services.AddAuthorization(o => o.AddPolicy("Owner", p => p.RequireRole("Owner")));
|
||||||
builder.Services.Configure<ForwardedHeadersOptions>(o =>
|
builder.Services.Configure<ForwardedHeadersOptions>(o =>
|
||||||
{
|
{
|
||||||
// Trust only HTTPS information from the configured host reverse proxy.
|
// Trust scheme and client address only from the explicitly configured host proxy.
|
||||||
// Client IP forwarding remains disabled until per-client limits are introduced.
|
// The rewritten RemoteIpAddress is used by login throttling below.
|
||||||
o.ForwardedHeaders = ForwardedHeaders.XForwardedProto;
|
o.ForwardedHeaders = ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedFor;
|
||||||
o.ForwardLimit = 1;
|
o.ForwardLimit = 1;
|
||||||
if (builder.Configuration["Proxy:KnownAddress"] is { Length: > 0 } address)
|
if (builder.Configuration["Proxy:KnownAddress"] is { Length: > 0 } address)
|
||||||
o.KnownProxies.Add(IPAddress.Parse(address));
|
o.KnownProxies.Add(IPAddress.Parse(address));
|
||||||
@@ -169,6 +169,7 @@ api.MapPut("/hotel", async (SettingsInput input, HttpContext c) =>
|
|||||||
await Session.Audit(store, c, "Updated hotel settings"); return Results.Ok(hotel);
|
await Session.Audit(store, c, "Updated hotel settings"); return Results.Ok(hotel);
|
||||||
}).RequireAuthorization("Owner");
|
}).RequireAuthorization("Owner");
|
||||||
api.MapGet("/conversations", async (HttpContext c, CancellationToken _) => Results.Ok((await store.List<Conversation>(Session.Hotel(c))).OrderByDescending(x => x.ReceivedAt)));
|
api.MapGet("/conversations", async (HttpContext c, CancellationToken _) => Results.Ok((await store.List<Conversation>(Session.Hotel(c))).OrderByDescending(x => x.ReceivedAt)));
|
||||||
|
api.MapGet("/conversations/page",async(string? cursor,HttpContext c)=>ConversationPaging.TryDecode(cursor,out var before,out var beforeId)?Results.Ok(await store.ConversationPage(Session.Hotel(c),cursor==null?null:before,beforeId,50)):Results.BadRequest(new{error="Invalid conversation cursor."}));
|
||||||
api.MapGet("/conversations/{id}", async (string id, HttpContext c) => await store.Get<Conversation>(Session.Hotel(c), id) is { } item ? Results.Ok(item) : Results.NotFound());
|
api.MapGet("/conversations/{id}", async (string id, HttpContext c) => await store.Get<Conversation>(Session.Hotel(c), id) is { } item ? Results.Ok(item) : Results.NotFound());
|
||||||
api.MapPut("/conversations/{id}/draft", async (string id, DraftInput input, HttpContext c) =>
|
api.MapPut("/conversations/{id}/draft", async (string id, DraftInput input, HttpContext c) =>
|
||||||
{
|
{
|
||||||
@@ -204,7 +205,7 @@ api.MapPut("/knowledge/{id}", async (string id, KnowledgeInput input, HttpContex
|
|||||||
await Session.Audit(store, c, "Updated hotel knowledge"); return Results.Ok(item);
|
await Session.Audit(store, c, "Updated hotel knowledge"); return Results.Ok(item);
|
||||||
}).RequireAuthorization("Owner");
|
}).RequireAuthorization("Owner");
|
||||||
api.MapGet("/activity", async (HttpContext c, CancellationToken _) => Results.Ok((await store.List<Activity>(Session.Hotel(c))).OrderByDescending(x => x.At).Take(100)));
|
api.MapGet("/activity", async (HttpContext c, CancellationToken _) => Results.Ok((await store.List<Activity>(Session.Hotel(c))).OrderByDescending(x => x.At).Take(100)));
|
||||||
api.MapGet("/mailboxes", async (HttpContext c, GoogleMailbox google, AiDrafts ai) => Results.Ok(new { configured = !preview && google.Configured, sendingConfigured = !preview && google.SendingConfigured, aiConfigured = !preview && ai.Configured, items = (await store.List<Mailbox>(Session.Hotel(c))).Select(MailboxManagement.View) }));
|
api.MapGet("/mailboxes", async (HttpContext c, GoogleMailbox google, AiDrafts ai) => { var hotel=Session.Hotel(c);return Results.Ok(new { configured = !preview && google.Configured, sendingConfigured = !preview && google.SendingConfigured, aiConfigured = !preview && ai.Configured, timeZone=(await store.Get<Hotel>(hotel,hotel))?.Timezone??"UTC", items = (await store.List<Mailbox>(hotel)).Select(MailboxManagement.View) }); });
|
||||||
api.MapPut("/reply-controls", async (ReplyControlsInput input, HttpContext c, GoogleMailbox google, AiDrafts ai) =>
|
api.MapPut("/reply-controls", async (ReplyControlsInput input, HttpContext c, GoogleMailbox google, AiDrafts ai) =>
|
||||||
{
|
{
|
||||||
if ((input.AiDraftsEnabled && (preview || !ai.Configured)) || (input.StaffSendingEnabled && (preview || !google.SendingConfigured))) return Results.BadRequest(new { error = "The administrator must configure this capability first." });
|
if ((input.AiDraftsEnabled && (preview || !ai.Configured)) || (input.StaffSendingEnabled && (preview || !google.SendingConfigured))) return Results.BadRequest(new { error = "The administrator must configure this capability first." });
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ public interface IStore
|
|||||||
Task<DateTime?> WorkerLastSeen();
|
Task<DateTime?> WorkerLastSeen();
|
||||||
Task RecordWorkerHeartbeat();
|
Task RecordWorkerHeartbeat();
|
||||||
Task<List<T>> List<T>(string hotel) where T : TenantDocument;
|
Task<List<T>> List<T>(string hotel) where T : TenantDocument;
|
||||||
|
Task<ConversationPage> ConversationPage(string hotel,DateTime? before,string beforeId,int limit);
|
||||||
Task<T?> Get<T>(string hotel, string id) where T : TenantDocument;
|
Task<T?> Get<T>(string hotel, string id) where T : TenantDocument;
|
||||||
Task Insert<T>(T document) where T : TenantDocument;
|
Task Insert<T>(T document) where T : TenantDocument;
|
||||||
Task<bool> Replace<T>(string hotel, string id, long version, T document) where T : TenantDocument;
|
Task<bool> Replace<T>(string hotel, string id, long version, T document) where T : TenantDocument;
|
||||||
@@ -78,6 +79,12 @@ public sealed class MongoStore : IStore
|
|||||||
if (typeof(T) == typeof(PmsChange) || typeof(T) == typeof(PaymentRequest)) query = query.Sort(Builders<T>.Sort.Descending("UpdatedAt"));
|
if (typeof(T) == typeof(PmsChange) || typeof(T) == typeof(PaymentRequest)) query = query.Sort(Builders<T>.Sort.Descending("UpdatedAt"));
|
||||||
return query.Limit(500).ToListAsync();
|
return query.Limit(500).ToListAsync();
|
||||||
}
|
}
|
||||||
|
public async Task<ConversationPage> ConversationPage(string hotel,DateTime? before,string beforeId,int limit)
|
||||||
|
{
|
||||||
|
var filter=Scope<Conversation>(hotel);if(before!=null)filter&=Builders<Conversation>.Filter.Lt(x=>x.ReceivedAt,before.Value)|(Builders<Conversation>.Filter.Eq(x=>x.ReceivedAt,before.Value)&Builders<Conversation>.Filter.Lt(x=>x.Id,beforeId));
|
||||||
|
var rows=await Collection<Conversation>().Find(filter).SortByDescending(x=>x.ReceivedAt).ThenByDescending(x=>x.Id).Limit(limit+1).ToListAsync();
|
||||||
|
var more=rows.Count>limit;if(more)rows.RemoveAt(rows.Count-1);return new(rows,more?ConversationPaging.Encode(rows[^1]):null);
|
||||||
|
}
|
||||||
public async Task<T?> Get<T>(string hotel, string id) where T : TenantDocument => await Collection<T>().Find(Scope<T>(hotel) & Builders<T>.Filter.Eq(x => x.Id, id)).FirstOrDefaultAsync();
|
public async Task<T?> Get<T>(string hotel, string id) where T : TenantDocument => await Collection<T>().Find(Scope<T>(hotel) & Builders<T>.Filter.Eq(x => x.Id, id)).FirstOrDefaultAsync();
|
||||||
public Task Insert<T>(T document) where T : TenantDocument
|
public Task Insert<T>(T document) where T : TenantDocument
|
||||||
{
|
{
|
||||||
@@ -179,6 +186,11 @@ public sealed class PreviewStore : IStore
|
|||||||
static string Json<T>(T value) => System.Text.Json.JsonSerializer.Serialize(value);
|
static string Json<T>(T value) => System.Text.Json.JsonSerializer.Serialize(value);
|
||||||
public Task Initialize() => Task.CompletedTask;
|
public Task Initialize() => Task.CompletedTask;
|
||||||
public Task<List<T>> List<T>(string hotel) where T : TenantDocument => Task.FromResult(rows.Where(x => x.Key.StartsWith(typeof(T).Name + ":")).Select(x => Clone<T>(x.Value)).Where(x => x.HotelId == hotel).ToList());
|
public Task<List<T>> List<T>(string hotel) where T : TenantDocument => Task.FromResult(rows.Where(x => x.Key.StartsWith(typeof(T).Name + ":")).Select(x => Clone<T>(x.Value)).Where(x => x.HotelId == hotel).ToList());
|
||||||
|
public async Task<ConversationPage> ConversationPage(string hotel,DateTime? before,string beforeId,int limit)
|
||||||
|
{
|
||||||
|
var query=(await List<Conversation>(hotel)).OrderByDescending(x=>x.ReceivedAt).ThenByDescending(x=>x.Id).Where(x=>before==null||x.ReceivedAt<before||x.ReceivedAt==before&&string.CompareOrdinal(x.Id,beforeId)<0).Take(limit+1).ToList();
|
||||||
|
var more=query.Count>limit;if(more)query.RemoveAt(query.Count-1);return new(query,more?ConversationPaging.Encode(query[^1]):null);
|
||||||
|
}
|
||||||
public async Task<T?> Get<T>(string hotel, string id) where T : TenantDocument => (await List<T>(hotel)).SingleOrDefault(x => x.Id == id);
|
public async Task<T?> Get<T>(string hotel, string id) where T : TenantDocument => (await List<T>(hotel)).SingleOrDefault(x => x.Id == id);
|
||||||
public Task Insert<T>(T document) where T : TenantDocument { if (!rows.TryAdd(Key<T>(document.Id), Json(document))) throw new InvalidOperationException("Duplicate document"); return Task.CompletedTask; }
|
public Task Insert<T>(T document) where T : TenantDocument { if (!rows.TryAdd(Key<T>(document.Id), Json(document))) throw new InvalidOperationException("Duplicate document"); return Task.CompletedTask; }
|
||||||
public Task<bool> Replace<T>(string hotel, string id, long version, T document) where T : TenantDocument
|
public Task<bool> Replace<T>(string hotel, string id, long version, T document) where T : TenantDocument
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ static class AutoReplyTests
|
|||||||
check("Unsupported subject context stays with staff",!(await work.Test(hotel.Id,"I need help with my insulin","Is parking available?")).Matches);
|
check("Unsupported subject context stays with staff",!(await work.Test(hotel.Id,"I need help with my insulin","Is parking available?")).Matches);
|
||||||
check("FAQ sensitive subject blocks an otherwise simple question",!(await work.Test(hotel.Id,"Refund for cancelled booking","Is parking available?")).Matches);
|
check("FAQ sensitive subject blocks an otherwise simple question",!(await work.Test(hotel.Id,"Refund for cancelled booking","Is parking available?")).Matches);
|
||||||
check("FAQ answer cannot cross hotel boundary",!(await work.Test("foreign","Parking","Is parking available?")).Matches);
|
check("FAQ answer cannot cross hotel boundary",!(await work.Test("foreign","Parking","Is parking available?")).Matches);
|
||||||
|
var evaluation=await work.Evaluate(hotel.Id,new[]{new AutoEvaluationCase("allowed","Parking","Is parking available?",true,answer.Id),new AutoEvaluationCase("extra-request","Parking","Is parking available? Also cancel my stay.",false)});
|
||||||
|
check("FAQ batch evaluation reports expected matches and exclusions",evaluation.Length==2&&evaluation.All(x=>x.Passed)&&evaluation[0].ActualKnowledgeId==answer.Id);
|
||||||
var m=await Process(Message());check("FAQ test mode records a match without delivery or quota use",m.AutoReplyMatched&&m.Delivery==null&&(await store.List<AutoReplyClaim>(hotel.Id)).Count==0);
|
var m=await Process(Message());check("FAQ test mode records a match without delivery or quota use",m.AutoReplyMatched&&m.Delivery==null&&(await store.List<AutoReplyClaim>(hotel.Id)).Count==0);
|
||||||
var v=answer.Version;answer.Version++;await store.Replace(hotel.Id,answer.Id,v,answer);check("Changed approved answer invalidates FAQ rule",!(await work.Test(hotel.Id,"Parking","Is parking available?")).Matches);
|
var v=answer.Version;answer.Version++;await store.Replace(hotel.Id,answer.Id,v,answer);check("Changed approved answer invalidates FAQ rule",!(await work.Test(hotel.Id,"Parking","Is parking available?")).Matches);
|
||||||
v=rule.Version;rule.KnowledgeVersion=answer.Version;rule.Version++;await store.Replace(hotel.Id,rule.Id,v,rule);
|
v=rule.Version;rule.KnowledgeVersion=answer.Version;rule.Version++;await store.Replace(hotel.Id,rule.Id,v,rule);
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ try
|
|||||||
await store.Import(row); await store.Import(row);
|
await store.Import(row); await store.Import(row);
|
||||||
Check("Duplicate email import is idempotent", (await store.List<Conversation>(a.Id)).Count == 1);
|
Check("Duplicate email import is idempotent", (await store.List<Conversation>(a.Id)).Count == 1);
|
||||||
Check("Inbox queries enforce hotel boundary", (await store.List<Conversation>(b.Id)).Count == 0);
|
Check("Inbox queries enforce hotel boundary", (await store.List<Conversation>(b.Id)).Count == 0);
|
||||||
|
var pagingHotel=new Hotel{Name="Paging hotel"};pagingHotel.HotelId=pagingHotel.Id;await store.Insert(pagingHotel);var pagingNow=DateTime.UtcNow;var pagingAt=new DateTime(pagingNow.Ticks-pagingNow.Ticks%TimeSpan.TicksPerMillisecond,DateTimeKind.Utc);
|
||||||
|
foreach(var id in new[]{"00000000000000000000000000000003","00000000000000000000000000000002","00000000000000000000000000000001"})await store.Insert(new Conversation{Id=id,HotelId=pagingHotel.Id,ReceivedAt=pagingAt,Subject=id});
|
||||||
|
var firstPage=await store.ConversationPage(pagingHotel.Id,null,"",2);Check("Conversation page has stable bounded cursor",firstPage.Items.Select(x=>x.Id).SequenceEqual(new[]{"00000000000000000000000000000003","00000000000000000000000000000002"})&&firstPage.NextCursor!=null);
|
||||||
|
Check("Conversation cursor round-trips safely",ConversationPaging.TryDecode(firstPage.NextCursor,out var pageAt,out var pageId)&&pageAt==pagingAt&&pageId=="00000000000000000000000000000002"&&!ConversationPaging.TryDecode("not-a-cursor",out _,out _));
|
||||||
|
var secondPage=await store.ConversationPage(pagingHotel.Id,pageAt,pageId,2);Check("Conversation pagination has no overlap or tenant leakage",secondPage.Items.Select(x=>x.Id).SequenceEqual(new[]{"00000000000000000000000000000001"})&&secondPage.NextCursor==null);
|
||||||
var altered = new Hotel { Id = a.Id, HotelId = a.Id, Name = "Updated", Version = 1 };
|
var altered = new Hotel { Id = a.Id, HotelId = a.Id, Name = "Updated", Version = 1 };
|
||||||
Check("Settings update succeeds with current version", await store.Replace(a.Id,a.Id,0,altered));
|
Check("Settings update succeeds with current version", await store.Replace(a.Id,a.Id,0,altered));
|
||||||
Check("Concurrent stale edit rejected", !await store.Replace(a.Id,a.Id,0,altered));
|
Check("Concurrent stale edit rejected", !await store.Replace(a.Id,a.Id,0,altered));
|
||||||
@@ -88,14 +93,14 @@ try
|
|||||||
var h1=await Read(one,"/api/hotel");var h2=await Read(two,"/api/hotel");
|
var h1=await Read(one,"/api/hotel");var h2=await Read(two,"/api/hotel");
|
||||||
Check("Different preview sessions have different hotels", h1.GetProperty("id").GetString()!=h2.GetProperty("id").GetString());
|
Check("Different preview sessions have different hotels", h1.GetProperty("id").GetString()!=h2.GetProperty("id").GetString());
|
||||||
var health=await Read(one,"/api/operations");
|
var health=await Read(one,"/api/operations");
|
||||||
Check("Health overview is hotel scoped and labels preview worker",health.GetProperty("mailboxes").GetProperty("total").GetInt32()==1&&health.GetProperty("worker").GetProperty("state").GetString()=="Preview");
|
Check("Health overview is hotel scoped and carries hotel timezone",health.GetProperty("mailboxes").GetProperty("total").GetInt32()==1&&health.GetProperty("worker").GetProperty("state").GetString()=="Preview"&&health.GetProperty("timeZone").GetString()=="Europe/London");
|
||||||
var messages=await Read(one,"/api/conversations"); var id=messages[0].GetProperty("id").GetString();
|
var messages=await Read(one,"/api/conversations"); var id=messages[0].GetProperty("id").GetString();
|
||||||
Check("Guessed message ID cannot be edited across hotels", (await two.PutAsJsonAsync($"/api/conversations/{id}/draft",new {draft="stolen",version=0})).StatusCode==HttpStatusCode.NotFound);
|
Check("Guessed message ID cannot be edited across hotels", (await two.PutAsJsonAsync($"/api/conversations/{id}/draft",new {draft="stolen",version=0})).StatusCode==HttpStatusCode.NotFound);
|
||||||
Check("Draft save succeeds", (await one.PutAsJsonAsync($"/api/conversations/{id}/draft",new {draft="Hello guest",version=0})).IsSuccessStatusCode);
|
Check("Draft save succeeds", (await one.PutAsJsonAsync($"/api/conversations/{id}/draft",new {draft="Hello guest",version=0})).IsSuccessStatusCode);
|
||||||
Check("Stale API draft save returns conflict", (await one.PutAsJsonAsync($"/api/conversations/{id}/draft",new {draft="old",version=0})).StatusCode==HttpStatusCode.Conflict);
|
Check("Stale API draft save returns conflict", (await one.PutAsJsonAsync($"/api/conversations/{id}/draft",new {draft="old",version=0})).StatusCode==HttpStatusCode.Conflict);
|
||||||
Check("Preview cannot connect real Gmail", !(await one.PostAsJsonAsync("/api/integrations/google/connect",new {})).IsSuccessStatusCode);
|
Check("Preview cannot connect real Gmail", !(await one.PostAsJsonAsync("/api/integrations/google/connect",new {})).IsSuccessStatusCode);
|
||||||
var boxes=await Read(one,"/api/mailboxes");var boxId=boxes.GetProperty("items")[0].GetProperty("id").GetString();
|
var boxes=await Read(one,"/api/mailboxes");var boxId=boxes.GetProperty("items")[0].GetProperty("id").GetString();
|
||||||
Check("Mailbox health includes recovery state without secrets",boxes.GetProperty("items")[0].GetProperty("syncErrorCode").GetString()=="ReconnectRequired"&&!boxes.GetRawText().Contains("protectedRefreshToken")&&!boxes.GetRawText().Contains("pageToken"));
|
Check("Mailbox health includes timezone and recovery state without secrets",boxes.GetProperty("timeZone").GetString()=="Europe/London"&&boxes.GetProperty("items")[0].GetProperty("syncErrorCode").GetString()=="ReconnectRequired"&&!boxes.GetRawText().Contains("protectedRefreshToken")&&!boxes.GetRawText().Contains("pageToken"));
|
||||||
foreach(var action in new[]{"disconnect","reconnect","retry"})Check("Other hotel cannot "+action+" a mailbox",(await two.PostAsJsonAsync($"/api/mailboxes/{boxId}/{action}",new{version=0})).StatusCode==HttpStatusCode.NotFound);
|
foreach(var action in new[]{"disconnect","reconnect","retry"})Check("Other hotel cannot "+action+" a mailbox",(await two.PostAsJsonAsync($"/api/mailboxes/{boxId}/{action}",new{version=0})).StatusCode==HttpStatusCode.NotFound);
|
||||||
Check("Preview recovery cannot change real Google state",(await one.PostAsJsonAsync($"/api/mailboxes/{boxId}/reconnect",new{version=0})).StatusCode==HttpStatusCode.BadRequest);
|
Check("Preview recovery cannot change real Google state",(await one.PostAsJsonAsync($"/api/mailboxes/{boxId}/reconnect",new{version=0})).StatusCode==HttpStatusCode.BadRequest);
|
||||||
Check("Preview cannot enable paid AI", (await one.PutAsJsonAsync("/api/reply-controls",new {version=0,aiDraftsEnabled=true,staffSendingEnabled=false})).StatusCode==HttpStatusCode.BadRequest);
|
Check("Preview cannot enable paid AI", (await one.PutAsJsonAsync("/api/reply-controls",new {version=0,aiDraftsEnabled=true,staffSendingEnabled=false})).StatusCode==HttpStatusCode.BadRequest);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
"""Exercise disposable CI containers through the host's trusted proxy address.
|
"""Exercise a disposable native deployment through the host's trusted proxy address.
|
||||||
|
|
||||||
The forwarded HTTPS header simulates Nginx TLS termination; this is never run
|
The forwarded HTTPS header simulates Nginx TLS termination; this is never run
|
||||||
against an existing hotel database. Cookie values and credentials are not logged.
|
against an existing hotel database. Cookie values and credentials are not logged.
|
||||||
@@ -35,7 +35,7 @@ def request(path, method="GET", data=None, expected=200):
|
|||||||
return json.loads(body) if "application/json" in response.headers.get("Content-Type", "") else body
|
return json.loads(body) if "application/json" in response.headers.get("Content-Type", "") else body
|
||||||
|
|
||||||
|
|
||||||
assert "root" in request("/"), "Container must serve the built React interface"
|
assert "root" in request("/"), "Native API must serve the built React interface"
|
||||||
request("/api/hotel", expected=401)
|
request("/api/hotel", expected=401)
|
||||||
session = request("/api/session")
|
session = request("/api/session")
|
||||||
assert session["preview"] is False and session["user"] is None
|
assert session["preview"] is False and session["user"] is None
|
||||||
@@ -60,18 +60,18 @@ assert "securityKey" not in payment_status
|
|||||||
request("/api/payments/controls", "PUT", {"version": 0, "enabled": True}, expected=400)
|
request("/api/payments/controls", "PUT", {"version": 0, "enabled": True}, expected=400)
|
||||||
assert request("/api/payments/requests") == []
|
assert request("/api/payments/requests") == []
|
||||||
hotel = request("/api/hotel")
|
hotel = request("/api/hotel")
|
||||||
assert "root" in request("/account"), "Container must serve account link page"
|
assert "root" in request("/account"), "Native API must serve account link page"
|
||||||
assert len(request("/api/onboarding")["steps"]) == 5
|
assert len(request("/api/onboarding")["steps"]) == 5
|
||||||
team = request("/api/team")
|
team = request("/api/team")
|
||||||
assert all("passwordHash" not in member and "securityStamp" not in member and "accountLinkHash" not in member for member in team)
|
assert all("passwordHash" not in member and "securityStamp" not in member and "accountLinkHash" not in member for member in team)
|
||||||
if "--read" in sys.argv:
|
if "--read" in sys.argv:
|
||||||
assert hotel["signature"] == "Persisted across container restart"
|
assert hotel["signature"] == "Persisted across service restart"
|
||||||
invited = next(member for member in team if member["email"] == "ci-staff@example.invalid")
|
invited = next(member for member in team if member["email"] == "deployment-staff@example.invalid")
|
||||||
assert invited["pending"] and not invited["active"] and invited["linkPurpose"] == "Invite"
|
assert invited["pending"] and not invited["active"] and invited["linkPurpose"] == "Invite"
|
||||||
else:
|
else:
|
||||||
hotel["signature"] = "Persisted across container restart"
|
hotel["signature"] = "Persisted across service restart"
|
||||||
request("/api/hotel", "PUT", hotel)
|
request("/api/hotel", "PUT", hotel)
|
||||||
invite = request("/api/team/invite", "POST", {"name": "CI Staff", "email": "ci-staff@example.invalid"})
|
invite = request("/api/team/invite", "POST", {"name": "Deployment Staff", "email": "deployment-staff@example.invalid"})
|
||||||
assert invite["link"].startswith("https://sandbox-guestops.futuresens.co.uk/account#token=")
|
assert invite["link"].startswith("https://sandbox-guestops.futuresens.co.uk/account#token=")
|
||||||
request("/api/auth/logout", "POST")
|
request("/api/auth/logout", "POST")
|
||||||
request("/api/hotel", expected=401)
|
request("/api/hotel", expected=401)
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import importlib.util
|
||||||
|
from pathlib import Path
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
spec = importlib.util.spec_from_file_location("desktop_acceptance", Path(__file__).resolve().parents[1] / "deploy" / "desktop_acceptance.py")
|
||||||
|
acceptance = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(acceptance)
|
||||||
|
|
||||||
|
|
||||||
|
def valid_record():
|
||||||
|
return {
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"system": "guestops-desktop-parity",
|
||||||
|
"dataClassification": "synthetic-only",
|
||||||
|
"desktopBaselineCommit": acceptance.DESKTOP_BASELINE,
|
||||||
|
"releaseCommit": "a" * 40,
|
||||||
|
"releaseRecordSha256": "b" * 64,
|
||||||
|
"environment": "https://sandbox-guestops.futuresens.co.uk",
|
||||||
|
"browser": {"name": "Microsoft Edge", "version": "140.0.0.0", "operatingSystem": "Windows 11"},
|
||||||
|
"viewport": {"width": 1440, "height": 900, "deviceScaleFactor": 1},
|
||||||
|
"hotelTimeZone": "Europe/London",
|
||||||
|
"operator": "Acceptance operator",
|
||||||
|
"reviewedBy": "Independent reviewer",
|
||||||
|
"startedAt": "2026-09-29T09:00:00Z",
|
||||||
|
"endedAt": "2026-09-29T10:00:00Z",
|
||||||
|
"reviewedAt": "2026-09-29T11:00:00Z",
|
||||||
|
"scenarios": [
|
||||||
|
{"id": scenario, "status": "pass", "evidence": [f"restricted-ticket-{index}"]}
|
||||||
|
for index, scenario in enumerate(sorted(acceptance.SCENARIOS), 1)
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class DesktopAcceptanceTests(unittest.TestCase):
|
||||||
|
def test_complete_record_passes(self):
|
||||||
|
acceptance.validate(valid_record())
|
||||||
|
|
||||||
|
def test_exact_scenarios_and_desktop_baseline_are_required(self):
|
||||||
|
record = valid_record();record["scenarios"].pop()
|
||||||
|
with self.assertRaisesRegex(ValueError, "exact desktop scenario"):
|
||||||
|
acceptance.validate(record)
|
||||||
|
record = valid_record();record["desktopBaselineCommit"] = "c" * 40
|
||||||
|
with self.assertRaisesRegex(ValueError, "reviewed desktop baseline"):
|
||||||
|
acceptance.validate(record)
|
||||||
|
|
||||||
|
def test_desktop_viewport_and_timezone_are_required(self):
|
||||||
|
record = valid_record();record["viewport"]["width"] = 1024
|
||||||
|
with self.assertRaisesRegex(ValueError, "Desktop viewport width"):
|
||||||
|
acceptance.validate(record)
|
||||||
|
record = valid_record();record["hotelTimeZone"] = "local browser time"
|
||||||
|
with self.assertRaisesRegex(ValueError, "IANA timezone"):
|
||||||
|
acceptance.validate(record)
|
||||||
|
|
||||||
|
def test_independent_review_and_safe_evidence_are_required(self):
|
||||||
|
record = valid_record();record["reviewedBy"] = record["operator"]
|
||||||
|
with self.assertRaisesRegex(ValueError, "different people"):
|
||||||
|
acceptance.validate(record)
|
||||||
|
record = valid_record();record["scenarios"][0]["evidence"] = ["guest@example.invalid"]
|
||||||
|
with self.assertRaisesRegex(ValueError, "safe opaque"):
|
||||||
|
acceptance.validate(record)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
import importlib.util
|
||||||
|
from pathlib import Path
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
|
||||||
|
|
||||||
|
def module(name):
|
||||||
|
spec = importlib.util.spec_from_file_location(name, ROOT / "deploy" / f"{name}.py")
|
||||||
|
result = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(result)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
automation = module("automation_acceptance")
|
||||||
|
privacy = module("identity_privacy_acceptance")
|
||||||
|
|
||||||
|
|
||||||
|
def base(system):
|
||||||
|
return {
|
||||||
|
"schemaVersion": 1, "system": system, "targetGate": "B",
|
||||||
|
"releaseCommit": "a" * 40, "releaseRecordSha256": "b" * 64,
|
||||||
|
"environment": "https://sandbox-guestops.futuresens.co.uk",
|
||||||
|
"operator": "Acceptance operator", "reviewedBy": "Independent reviewer",
|
||||||
|
"startedAt": "2026-10-01T09:00:00Z", "endedAt": "2026-10-01T10:00:00Z", "reviewedAt": "2026-10-01T11:00:00Z",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def automation_record():
|
||||||
|
record = base("guestops-automation-acceptance")
|
||||||
|
record.update({
|
||||||
|
"dataClassification": "synthetic-only",
|
||||||
|
"faqEvaluation": {"positiveCases": 20, "negativeCases": 20, "falsePositives": 0, "falseNegatives": 0, "reportSha256": "c" * 64},
|
||||||
|
"aiEvaluation": {"casesReviewed": 20, "unsafeDraftsApproved": 0, "reportSha256": "d" * 64},
|
||||||
|
"staffTrained": 3, "monitoringOwner": "Monitoring owner", "rollbackOwner": "Rollback owner",
|
||||||
|
"scenarios": [{"id": item, "status": "pass", "evidence": ["restricted-" + item]} for item in sorted(automation.SCENARIOS)],
|
||||||
|
"postAcceptanceState": {"faqMode": "off", "pmsWrites": "disabled", "paymentCreation": "disabled"},
|
||||||
|
})
|
||||||
|
return record
|
||||||
|
|
||||||
|
|
||||||
|
def privacy_record():
|
||||||
|
record = base("guestops-identity-privacy")
|
||||||
|
record.update({
|
||||||
|
"retention": {"conversationDays": 365, "auditDays": 730, "backupDays": 30, "accountDays": 730,
|
||||||
|
"privacyOwner": "Privacy owner", "deletionOwner": "Deletion owner", "legalHoldOwner": "Legal hold owner",
|
||||||
|
"deletionProcedure": "restricted-deletion", "legalHoldProcedure": "restricted-legal-hold"},
|
||||||
|
"providers": {"google": {"status": "accepted", "evidence": ["restricted-google"]},
|
||||||
|
"openai": {"status": "disabled", "evidence": ["restricted-openai-decision"]}},
|
||||||
|
"preferencesReviewed": sorted(privacy.PREFERENCES),
|
||||||
|
"scenarios": [{"id": item, "status": "pass", "evidence": ["restricted-" + item]} for item in sorted(privacy.SCENARIOS)],
|
||||||
|
})
|
||||||
|
return record
|
||||||
|
|
||||||
|
|
||||||
|
class GateBAcceptanceTests(unittest.TestCase):
|
||||||
|
def test_complete_records_pass(self):
|
||||||
|
automation.validate(automation_record())
|
||||||
|
privacy.validate(privacy_record())
|
||||||
|
|
||||||
|
def test_automation_requires_zero_faq_errors_and_training(self):
|
||||||
|
record = automation_record();record["faqEvaluation"]["falsePositives"] = 1
|
||||||
|
with self.assertRaisesRegex(ValueError, "zero false positives"):
|
||||||
|
automation.validate(record)
|
||||||
|
record = automation_record();record["staffTrained"] = 0
|
||||||
|
with self.assertRaisesRegex(ValueError, "staff member"):
|
||||||
|
automation.validate(record)
|
||||||
|
|
||||||
|
def test_privacy_requires_retention_and_google_decisions(self):
|
||||||
|
record = privacy_record();record["retention"]["conversationDays"] = 0
|
||||||
|
with self.assertRaisesRegex(ValueError, "conversationDays"):
|
||||||
|
privacy.validate(record)
|
||||||
|
record = privacy_record();record["providers"]["google"]["status"] = "pending"
|
||||||
|
with self.assertRaisesRegex(ValueError, "Google processing"):
|
||||||
|
privacy.validate(record)
|
||||||
|
|
||||||
|
def test_privacy_requires_exact_preference_coverage(self):
|
||||||
|
record = privacy_record();record["preferencesReviewed"].pop()
|
||||||
|
with self.assertRaisesRegex(ValueError, "exact owner-controlled"):
|
||||||
|
privacy.validate(record)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import importlib.util
|
||||||
|
from pathlib import Path
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
spec = importlib.util.spec_from_file_location("google_acceptance", Path(__file__).resolve().parents[1] / "deploy" / "google_acceptance.py")
|
||||||
|
acceptance = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(acceptance)
|
||||||
|
|
||||||
|
|
||||||
|
def valid_report():
|
||||||
|
return {
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"system": "google-mailbox",
|
||||||
|
"releaseCommit": "a" * 40,
|
||||||
|
"releaseRecordSha256": "b" * 64,
|
||||||
|
"environment": "https://sandbox-guestops.futuresens.co.uk",
|
||||||
|
"mailboxLabel": "sandbox mailbox A",
|
||||||
|
"operator": "Test operator",
|
||||||
|
"startedAt": "2026-09-29T10:00:00Z",
|
||||||
|
"endedAt": "2026-09-29T11:00:00Z",
|
||||||
|
"acceptedAt": "2026-09-29T12:00:00Z",
|
||||||
|
"acceptedBy": "Test approver",
|
||||||
|
"scenarios": [
|
||||||
|
{"id": scenario, "status": "pass", "evidence": [f"restricted-ticket-{index}"]}
|
||||||
|
for index, scenario in enumerate(sorted(acceptance.SCENARIOS), 1)
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class GoogleAcceptanceTests(unittest.TestCase):
|
||||||
|
def test_complete_record_is_accepted(self):
|
||||||
|
acceptance.validate(valid_report())
|
||||||
|
|
||||||
|
def test_missing_or_unpassed_scenario_is_rejected(self):
|
||||||
|
report = valid_report()
|
||||||
|
report["scenarios"].pop()
|
||||||
|
with self.assertRaisesRegex(ValueError, "exact required scenario"):
|
||||||
|
acceptance.validate(report)
|
||||||
|
report = valid_report()
|
||||||
|
report["scenarios"][0]["status"] = "not-run"
|
||||||
|
with self.assertRaisesRegex(ValueError, "has not passed"):
|
||||||
|
acceptance.validate(report)
|
||||||
|
|
||||||
|
def test_record_rejects_email_addresses_and_insecure_origin(self):
|
||||||
|
report = valid_report()
|
||||||
|
report["mailboxLabel"] = "real-address@example.invalid"
|
||||||
|
with self.assertRaisesRegex(ValueError, "non-email alias"):
|
||||||
|
acceptance.validate(report)
|
||||||
|
report = valid_report()
|
||||||
|
report["environment"] = "http://sandbox.example.invalid/path"
|
||||||
|
with self.assertRaisesRegex(ValueError, "HTTPS origin"):
|
||||||
|
acceptance.validate(report)
|
||||||
|
|
||||||
|
def test_record_rejects_bad_timestamps_and_evidence(self):
|
||||||
|
report = valid_report()
|
||||||
|
report["acceptedAt"] = "2026-09-29T09:00:00Z"
|
||||||
|
with self.assertRaisesRegex(ValueError, "out of order"):
|
||||||
|
acceptance.validate(report)
|
||||||
|
report = valid_report()
|
||||||
|
report["scenarios"][0]["evidence"] = ["guest@example.invalid"]
|
||||||
|
with self.assertRaisesRegex(ValueError, "invalid evidence"):
|
||||||
|
acceptance.validate(report)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
import importlib.util
|
||||||
|
from pathlib import Path
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
spec = importlib.util.spec_from_file_location("incident_exercise", Path(__file__).resolve().parents[1] / "deploy" / "incident_exercise.py")
|
||||||
|
exercise = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(exercise)
|
||||||
|
|
||||||
|
|
||||||
|
def valid_record(gate="B"):
|
||||||
|
required = exercise.GATE_C_SCENARIOS if gate == "C" else exercise.GATE_B_SCENARIOS
|
||||||
|
return {
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"system": "guestops-incident-exercise",
|
||||||
|
"targetGate": gate,
|
||||||
|
"dataClassification": "synthetic-only",
|
||||||
|
"releaseCommit": "a" * 40,
|
||||||
|
"releaseRecordSha256": "b" * 64,
|
||||||
|
"environment": "https://sandbox-guestops.futuresens.co.uk",
|
||||||
|
"operator": "Exercise operator",
|
||||||
|
"incidentCommander": "Incident commander",
|
||||||
|
"reviewedBy": "Independent reviewer",
|
||||||
|
"startedAt": "2026-09-29T09:00:00Z",
|
||||||
|
"endedAt": "2026-09-29T10:00:00Z",
|
||||||
|
"reviewedAt": "2026-09-29T11:00:00Z",
|
||||||
|
"targetsMinutes": {"detection": 10, "containment": 20, "recovery": 60},
|
||||||
|
"observedMinutes": {"detection": 5, "containment": 15, "recovery": 45},
|
||||||
|
"scenarios": [
|
||||||
|
{"id": scenario, "status": "pass", "evidence": [f"restricted-ticket-{index}"]}
|
||||||
|
for index, scenario in enumerate(sorted(required), 1)
|
||||||
|
],
|
||||||
|
"postExerciseState": {
|
||||||
|
"externalWrites": "disabled", "faqMode": "off", "unresolvedOperations": 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class IncidentExerciseTests(unittest.TestCase):
|
||||||
|
def test_gate_b_and_c_complete_records_pass(self):
|
||||||
|
exercise.validate(valid_record("B"))
|
||||||
|
exercise.validate(valid_record("C"))
|
||||||
|
|
||||||
|
def test_gate_specific_scenarios_are_required(self):
|
||||||
|
record = valid_record("C")
|
||||||
|
record["scenarios"].pop()
|
||||||
|
with self.assertRaisesRegex(ValueError, "exact incident scenario"):
|
||||||
|
exercise.validate(record)
|
||||||
|
|
||||||
|
def test_timings_must_meet_preagreed_targets(self):
|
||||||
|
record = valid_record()
|
||||||
|
record["observedMinutes"]["containment"] = 21
|
||||||
|
with self.assertRaisesRegex(ValueError, "Observed containment"):
|
||||||
|
exercise.validate(record)
|
||||||
|
record = valid_record()
|
||||||
|
record["targetsMinutes"]["recovery"] = True
|
||||||
|
with self.assertRaisesRegex(ValueError, "recovery target"):
|
||||||
|
exercise.validate(record)
|
||||||
|
|
||||||
|
def test_independent_people_and_safe_evidence_are_required(self):
|
||||||
|
record = valid_record()
|
||||||
|
record["reviewedBy"] = record["operator"]
|
||||||
|
with self.assertRaisesRegex(ValueError, "different people"):
|
||||||
|
exercise.validate(record)
|
||||||
|
record = valid_record()
|
||||||
|
record["scenarios"][0]["evidence"] = ["guest@example.invalid"]
|
||||||
|
with self.assertRaisesRegex(ValueError, "safe opaque"):
|
||||||
|
exercise.validate(record)
|
||||||
|
|
||||||
|
def test_safe_post_exercise_state_is_required(self):
|
||||||
|
record = valid_record()
|
||||||
|
record["postExerciseState"]["externalWrites"] = "enabled"
|
||||||
|
with self.assertRaisesRegex(ValueError, "writes disabled"):
|
||||||
|
exercise.validate(record)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
import contextlib
|
|
||||||
import hashlib
|
|
||||||
import importlib.util
|
|
||||||
import io
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
|
||||||
import tarfile
|
|
||||||
import tempfile
|
|
||||||
import unittest
|
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
spec = importlib.util.spec_from_file_location("ops", Path(__file__).resolve().parents[1] / "deploy" / "ops.py")
|
|
||||||
ops = importlib.util.module_from_spec(spec)
|
|
||||||
spec.loader.exec_module(ops)
|
|
||||||
|
|
||||||
|
|
||||||
class ArchiveTests(unittest.TestCase):
|
|
||||||
def test_empty_provider_templates_are_not_secret_configuration(self):
|
|
||||||
for section, target in (("Pms", "/run/guestops/pms.json"), ("Payments", "/run/guestops/payments.json")):
|
|
||||||
self.assertFalse(ops.provider_configured({section: {"Hotels": {}}}, target))
|
|
||||||
self.assertTrue(ops.provider_configured({section: {"Hotels": {"fixture": {"Key": "fixture"}}}}, target))
|
|
||||||
self.assertTrue(ops.provider_configured({section: {"Unknown": "fixture"}}, target))
|
|
||||||
|
|
||||||
def bundle(self, root, change=None):
|
|
||||||
files = {name: b"fixture backup data" for name in ops.FILES - {"manifest.json"}}
|
|
||||||
files["manifest.json"] = json.dumps({"format": 1, "sha256": {name: hashlib.sha256(data).hexdigest() for name, data in files.items()}}).encode()
|
|
||||||
target = root / "bundle.tar"
|
|
||||||
with tarfile.open(target, "w") as archive:
|
|
||||||
for name, data in files.items():
|
|
||||||
member = tarfile.TarInfo(name); member.size = len(data)
|
|
||||||
if change:
|
|
||||||
change(member)
|
|
||||||
archive.addfile(member, io.BytesIO(data) if member.isfile() else None)
|
|
||||||
return target
|
|
||||||
|
|
||||||
def test_checked_archive_roundtrip(self):
|
|
||||||
with tempfile.TemporaryDirectory() as temp:
|
|
||||||
root = Path(temp); dest = root / "dest"; dest.mkdir()
|
|
||||||
self.assertEqual(ops.unpack(self.bundle(root), dest)["format"], 1)
|
|
||||||
|
|
||||||
def test_path_escape_rejected(self):
|
|
||||||
with tempfile.TemporaryDirectory() as temp:
|
|
||||||
root = Path(temp); dest = root / "dest"; dest.mkdir()
|
|
||||||
def corrupt(member):
|
|
||||||
if member.name == "configuration.json": member.name = "../outside"
|
|
||||||
with self.assertRaisesRegex(RuntimeError, "Unexpected backup members"):
|
|
||||||
ops.unpack(self.bundle(root, corrupt), dest)
|
|
||||||
self.assertFalse((root / "outside").exists())
|
|
||||||
|
|
||||||
def test_symlink_rejected(self):
|
|
||||||
with tempfile.TemporaryDirectory() as temp:
|
|
||||||
root = Path(temp); dest = root / "dest"; dest.mkdir()
|
|
||||||
def corrupt(member):
|
|
||||||
if member.name == "configuration.json": member.type = tarfile.SYMTYPE; member.linkname = "/etc/passwd"; member.size = 0
|
|
||||||
with self.assertRaisesRegex(RuntimeError, "Invalid or oversized"):
|
|
||||||
ops.unpack(self.bundle(root, corrupt), dest)
|
|
||||||
|
|
||||||
def test_checksum_mismatch_rejected(self):
|
|
||||||
with tempfile.TemporaryDirectory() as temp:
|
|
||||||
root = Path(temp); dest = root / "dest"; dest.mkdir()
|
|
||||||
with patch.object(ops, "digest", return_value="changed"):
|
|
||||||
with self.assertRaisesRegex(RuntimeError, "checksum"):
|
|
||||||
ops.unpack(self.bundle(root), dest)
|
|
||||||
|
|
||||||
def test_backup_requires_explicit_maintenance(self):
|
|
||||||
with self.assertRaisesRegex(RuntimeError, "confirm-maintenance"):
|
|
||||||
ops.backup(type("Args", (), {"confirm_maintenance": False})())
|
|
||||||
|
|
||||||
@unittest.skipUnless(os.name == "posix", "Linux file permission semantics")
|
|
||||||
def test_dump_failure_restarts_services_and_ttl(self):
|
|
||||||
with tempfile.TemporaryDirectory() as temp:
|
|
||||||
calls = []
|
|
||||||
def compose(*args, **kwargs):
|
|
||||||
calls.append(args)
|
|
||||||
if args[0] == "ps": return b"a" * 64
|
|
||||||
if "sh" in args: raise RuntimeError("Simulated dump failure")
|
|
||||||
return b""
|
|
||||||
def mongo(script):
|
|
||||||
calls.append((script,))
|
|
||||||
if "getParameter" in script: return b"true"
|
|
||||||
if "storageSize" in script: return b'{"bytes":1,"collections":{}}'
|
|
||||||
return b""
|
|
||||||
def run(args, **kwargs):
|
|
||||||
return b'[{"Image":"sha256:fixture"}]' if "inspect" in args else b""
|
|
||||||
args = type("Args", (), {"confirm_maintenance": True, "recipient": "A" * 40, "output": str(Path(temp) / "backup.gpg")})()
|
|
||||||
with patch.object(ops, "configuration", return_value={}), patch.object(ops, "run", side_effect=run), patch.object(ops, "compose", side_effect=compose), patch.object(ops, "mongo", side_effect=mongo), patch.object(ops, "maintenance_lock", return_value=contextlib.nullcontext()):
|
|
||||||
with self.assertRaisesRegex(RuntimeError, "Simulated dump failure"):
|
|
||||||
ops.backup(args)
|
|
||||||
self.assertIn(("start", "api", "worker"), calls)
|
|
||||||
self.assertTrue(any("ttlMonitorEnabled:true" in call[0] for call in calls))
|
|
||||||
self.assertFalse(Path(args.output).exists())
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
||||||
|
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
import importlib.util
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
import subprocess
|
||||||
|
import tarfile
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
spec = importlib.util.spec_from_file_location("package_release", ROOT / "deploy" / "package_release.py")
|
||||||
|
package_release = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(package_release)
|
||||||
|
|
||||||
|
|
||||||
|
def run(repository: Path, *arguments: str) -> str:
|
||||||
|
result = subprocess.run(
|
||||||
|
["git", "-C", str(repository), *arguments],
|
||||||
|
check=True,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
return result.stdout.strip()
|
||||||
|
|
||||||
|
|
||||||
|
class PackageReleaseTests(unittest.TestCase):
|
||||||
|
def repository(self, root: Path, dotnet_version: str = "1.2.3", web_version: str = "1.2.3") -> tuple[Path, str]:
|
||||||
|
repository = root / "repository"
|
||||||
|
(repository / "web").mkdir(parents=True)
|
||||||
|
(repository / "src" / "GuestOps.Api").mkdir(parents=True)
|
||||||
|
(repository / "src" / "GuestOps.Worker").mkdir(parents=True)
|
||||||
|
run(repository, "init")
|
||||||
|
run(repository, "config", "user.name", "GuestOps Test")
|
||||||
|
run(repository, "config", "user.email", "guestops@example.invalid")
|
||||||
|
run(repository, "config", "core.autocrlf", "false")
|
||||||
|
(repository / "Directory.Build.props").write_text(
|
||||||
|
f"<Project><PropertyGroup><Version>{dotnet_version}</Version></PropertyGroup></Project>\n",
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
(repository / "web" / "package.json").write_text(
|
||||||
|
json.dumps({"version": web_version}) + "\n", encoding="utf-8"
|
||||||
|
)
|
||||||
|
(repository / "application.txt").write_text("committed application\n", encoding="utf-8")
|
||||||
|
run(repository, "add", ".")
|
||||||
|
run(repository, "commit", "-m", "fixture")
|
||||||
|
return repository, run(repository, "rev-parse", "HEAD")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def fake_builder(arguments, working_directory: Path) -> None:
|
||||||
|
if list(arguments[:3]) == ["npm", "run", "build"]:
|
||||||
|
content = (working_directory.parent / "application.txt").read_text(encoding="utf-8")
|
||||||
|
(working_directory / "dist").mkdir()
|
||||||
|
(working_directory / "dist" / "index.html").write_text(content, encoding="utf-8")
|
||||||
|
if arguments[0:2] == ["dotnet", "publish"]:
|
||||||
|
output = Path(arguments[arguments.index("--output") + 1])
|
||||||
|
executable = "GuestOps.Api" if "GuestOps.Api" in arguments[2] else "GuestOps.Worker"
|
||||||
|
(output / executable).write_bytes(executable.encode("ascii"))
|
||||||
|
|
||||||
|
def test_packages_only_selected_commit_as_native_release(self):
|
||||||
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
|
root = Path(directory)
|
||||||
|
repository, commit = self.repository(root)
|
||||||
|
(repository / "application.txt").write_text("uncommitted change\n", encoding="utf-8")
|
||||||
|
|
||||||
|
archive, details = package_release.build_package(
|
||||||
|
repository, commit, root / "output", self.fake_builder
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(archive.name, "guestops_1.2.3.tar.gz")
|
||||||
|
self.assertEqual(details, {"commit": commit, "version": "1.2.3", "runtime": "linux-x64"})
|
||||||
|
with tarfile.open(archive, "r:gz") as package:
|
||||||
|
names = package.getnames()
|
||||||
|
self.assertIn("guestops_1.2.3/api/GuestOps.Api", names)
|
||||||
|
self.assertIn("guestops_1.2.3/worker/GuestOps.Worker", names)
|
||||||
|
index = package.extractfile("guestops_1.2.3/api/wwwroot/index.html")
|
||||||
|
self.assertEqual(index.read().decode("utf-8").strip(), "committed application")
|
||||||
|
self.assertEqual(package.getmember("guestops_1.2.3/api/GuestOps.Api").mode, 0o755)
|
||||||
|
self.assertEqual(package.getmember("guestops_1.2.3/worker/GuestOps.Worker").mode, 0o755)
|
||||||
|
|
||||||
|
def test_same_commit_produces_identical_package(self):
|
||||||
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
|
root = Path(directory)
|
||||||
|
repository, commit = self.repository(root)
|
||||||
|
first, _ = package_release.build_package(repository, commit, root / "first", self.fake_builder)
|
||||||
|
second, _ = package_release.build_package(repository, commit, root / "second", self.fake_builder)
|
||||||
|
self.assertEqual(first.read_bytes(), second.read_bytes())
|
||||||
|
|
||||||
|
def test_rejects_mismatched_versions_and_existing_output(self):
|
||||||
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
|
root = Path(directory)
|
||||||
|
repository, commit = self.repository(root, web_version="1.2.4")
|
||||||
|
with self.assertRaisesRegex(ValueError, "versions differ"):
|
||||||
|
package_release.build_package(repository, commit, root / "output", self.fake_builder)
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
|
root = Path(directory)
|
||||||
|
repository, commit = self.repository(root)
|
||||||
|
package_release.build_package(repository, commit, root / "output", self.fake_builder)
|
||||||
|
with self.assertRaisesRegex(ValueError, "not overwritten"):
|
||||||
|
package_release.build_package(repository, commit, root / "output", self.fake_builder)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
import importlib.util
|
||||||
|
from pathlib import Path
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
spec = importlib.util.spec_from_file_location("pilot_approval", Path(__file__).resolve().parents[1] / "deploy" / "pilot_approval.py")
|
||||||
|
approval = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(approval)
|
||||||
|
|
||||||
|
|
||||||
|
def valid_record(gate="B"):
|
||||||
|
ids = approval.GATE_C if gate == "C" else approval.GATE_B
|
||||||
|
return {
|
||||||
|
"schemaVersion": 2, "targetGate": gate, "decision": "approved",
|
||||||
|
"releaseCommit": "a" * 40, "releaseRecordSha256": "b" * 64,
|
||||||
|
"decidedAt": "2026-09-29T12:00:00Z",
|
||||||
|
"approvals": {
|
||||||
|
"hotelOwner": {"name": "Hotel owner", "approvedAt": "2026-09-29T11:00:00Z"},
|
||||||
|
"technicalOwner": {"name": "Technical owner", "approvedAt": "2026-09-29T11:30:00Z"},
|
||||||
|
},
|
||||||
|
"capacity": {"reportSha256": "c" * 64, "hostMetricsSha256": "d" * 64, "targetConcurrency": 10, "observedConcurrency": 10, "targetP95Ms": 500, "observedP95Ms": 250, "targetErrorRate": 0.01, "observedErrorRate": 0, "targetCpuHeadroomPercent": 25, "observedCpuHeadroomPercent": 40, "targetMemoryHeadroomPercent": 25, "observedMemoryHeadroomPercent": 35},
|
||||||
|
"pilot": {"recordSha256": "e" * 64, "businessDaysObserved": 5, "hotelsObserved": 1, "stopConditionsObserved": 0, "unresolvedFindings": 0},
|
||||||
|
"evidence": [{"id": item, "status": "pass", "references": ["restricted-ticket-" + item]} for item in sorted(ids)],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class PilotApprovalTests(unittest.TestCase):
|
||||||
|
def test_gate_b_and_c_complete_records_pass(self):
|
||||||
|
approval.validate(valid_record("B"))
|
||||||
|
approval.validate(valid_record("C"))
|
||||||
|
|
||||||
|
def test_pending_or_missing_evidence_fails(self):
|
||||||
|
record = valid_record();record["decision"] = "pending"
|
||||||
|
with self.assertRaisesRegex(ValueError, "explicit approved"):
|
||||||
|
approval.validate(record)
|
||||||
|
record = valid_record();record["evidence"].pop()
|
||||||
|
with self.assertRaisesRegex(ValueError, "exact evidence"):
|
||||||
|
approval.validate(record)
|
||||||
|
|
||||||
|
def test_capacity_must_meet_preapproved_targets(self):
|
||||||
|
record = valid_record();record["capacity"]["observedP95Ms"] = 501
|
||||||
|
with self.assertRaisesRegex(ValueError, "observedP95Ms"):
|
||||||
|
approval.validate(record)
|
||||||
|
record = valid_record();record["capacity"]["observedConcurrency"] = 9
|
||||||
|
with self.assertRaisesRegex(ValueError, "Observed concurrency"):
|
||||||
|
approval.validate(record)
|
||||||
|
record = valid_record();record["capacity"]["targetConcurrency"] = True
|
||||||
|
with self.assertRaisesRegex(ValueError, "Observed concurrency"):
|
||||||
|
approval.validate(record)
|
||||||
|
record = valid_record();record["capacity"]["targetErrorRate"] = 2
|
||||||
|
with self.assertRaisesRegex(ValueError, "ratio"):
|
||||||
|
approval.validate(record)
|
||||||
|
record = valid_record();record["capacity"]["observedCpuHeadroomPercent"] = 24
|
||||||
|
with self.assertRaisesRegex(ValueError, "cpu headroom"):
|
||||||
|
approval.validate(record)
|
||||||
|
|
||||||
|
def test_completed_five_day_single_hotel_pilot_is_required(self):
|
||||||
|
record = valid_record();record["pilot"]["businessDaysObserved"] = 4
|
||||||
|
with self.assertRaisesRegex(ValueError, "five business days"):
|
||||||
|
approval.validate(record)
|
||||||
|
record = valid_record();record["pilot"]["stopConditionsObserved"] = 1
|
||||||
|
with self.assertRaisesRegex(ValueError, "stop condition"):
|
||||||
|
approval.validate(record)
|
||||||
|
|
||||||
|
def test_approvers_must_be_separate_people_without_email_addresses(self):
|
||||||
|
record = valid_record();record["approvals"]["technicalOwner"]["name"] = "Hotel owner"
|
||||||
|
with self.assertRaisesRegex(ValueError, "different people"):
|
||||||
|
approval.validate(record)
|
||||||
|
record = valid_record();record["approvals"]["hotelOwner"]["name"] = "owner@example.invalid"
|
||||||
|
with self.assertRaisesRegex(ValueError, "without an email"):
|
||||||
|
approval.validate(record)
|
||||||
|
|
||||||
|
def test_containment_requires_owner_future_expiry_and_trigger(self):
|
||||||
|
record = valid_record();item = record["evidence"][0];item["status"] = "contained"
|
||||||
|
with self.assertRaisesRegex(ValueError, "containment details"):
|
||||||
|
approval.validate(record)
|
||||||
|
item["containment"] = {"owner": "Release owner", "expiresAt": "2026-10-10T12:00:00Z", "rollbackTrigger": "Rollback if the contained condition occurs."}
|
||||||
|
approval.validate(record)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import importlib.util
|
||||||
|
from pathlib import Path
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
spec = importlib.util.spec_from_file_location("pilot_run", Path(__file__).resolve().parents[1] / "deploy" / "pilot_run.py")
|
||||||
|
pilot = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(pilot)
|
||||||
|
|
||||||
|
|
||||||
|
def valid_record():
|
||||||
|
days = [f"2026-10-{day:02d}" for day in range(5, 10)]
|
||||||
|
return {
|
||||||
|
"schemaVersion": 1, "system": "guestops-supervised-pilot", "targetGate": "B",
|
||||||
|
"releaseCommit": "a" * 40, "releaseRecordSha256": "b" * 64,
|
||||||
|
"environment": "https://sandbox-guestops.futuresens.co.uk", "hotelLabel": "pilot-hotel-a",
|
||||||
|
"hotelCount": 1, "plannedBusinessDays": 5,
|
||||||
|
"owners": {"hotelOwner": "Hotel owner", "technicalOwner": "Technical owner", "rollbackDecisionMaker": "Technical owner"},
|
||||||
|
"startedOn": days[0], "endedOn": days[-1],
|
||||||
|
"pilotControls": {"pmsWrites": "disabled", "paymentCreation": "disabled", "faqMode": "off", "googleReviewedSending": "accepted"},
|
||||||
|
"dailyReviews": [{"date": day, "status": "pass", "reviewedBy": "Daily reviewer", "evidence": [f"restricted-{day}"]} for day in days],
|
||||||
|
"stopConditions": {condition: False for condition in pilot.STOP_CONDITIONS},
|
||||||
|
"findings": [],
|
||||||
|
"postPilotState": {"pmsWrites": "disabled", "paymentCreation": "disabled", "faqMode": "off"},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class PilotRunTests(unittest.TestCase):
|
||||||
|
def test_complete_five_day_record_passes(self):
|
||||||
|
pilot.validate(valid_record())
|
||||||
|
|
||||||
|
def test_exact_business_days_are_required(self):
|
||||||
|
record = valid_record();record["dailyReviews"].pop()
|
||||||
|
with self.assertRaisesRegex(ValueError, "Exactly five"):
|
||||||
|
pilot.validate(record)
|
||||||
|
record = valid_record();record["dailyReviews"][1]["date"] = "2026-10-07"
|
||||||
|
with self.assertRaisesRegex(ValueError, "each business day"):
|
||||||
|
pilot.validate(record)
|
||||||
|
|
||||||
|
def test_stop_condition_prevents_pass(self):
|
||||||
|
record = valid_record();record["stopConditions"]["duplicate-send"] = True
|
||||||
|
with self.assertRaisesRegex(ValueError, "stop condition"):
|
||||||
|
pilot.validate(record)
|
||||||
|
|
||||||
|
def test_critical_findings_cannot_be_contained(self):
|
||||||
|
record = valid_record();record["findings"] = [{"id": "security-001", "severity": "critical", "disposition": "contained", "evidence": ["restricted-finding"]}]
|
||||||
|
with self.assertRaisesRegex(ValueError, "too severe"):
|
||||||
|
pilot.validate(record)
|
||||||
|
|
||||||
|
def test_lower_severity_containment_requires_owner_expiry_and_trigger(self):
|
||||||
|
record = valid_record();record["findings"] = [{"id": "usability-001", "severity": "low", "disposition": "contained", "evidence": ["restricted-finding"]}]
|
||||||
|
with self.assertRaisesRegex(ValueError, "containment details"):
|
||||||
|
pilot.validate(record)
|
||||||
|
record["findings"][0]["containment"] = {"owner": "Finding owner", "expiresAt": "2026-10-31T12:00:00Z", "rollbackTrigger": "Stop if the issue affects guest handling."}
|
||||||
|
pilot.validate(record)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "guestops-web",
|
"name": "guestops-web",
|
||||||
"version": "0.1.0",
|
"version": "0.2.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "guestops-web",
|
"name": "guestops-web",
|
||||||
"version": "0.1.0",
|
"version": "0.2.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lucide-react": "^0.577.0",
|
"lucide-react": "^0.577.0",
|
||||||
"react": "19.2.8",
|
"react": "19.2.8",
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
{"name":"guestops-web","private":true,"version":"0.1.0","type":"module","scripts":{"dev":"vite --host 127.0.0.1","build":"tsc -b && vite build","check":"tsc -b"},"dependencies":{"react":"19.2.8","react-dom":"19.2.8","lucide-react":"^0.577.0"},"devDependencies":{"@types/react":"^19.2.0","@types/react-dom":"^19.2.0","@vitejs/plugin-react":"6.1.1","typescript":"~5.9.3","vite":"8.2.2"}}
|
{"name":"guestops-web","private":true,"version":"0.2.2","type":"module","scripts":{"dev":"vite --host 127.0.0.1","build":"tsc -b && vite build","check":"tsc -b"},"dependencies":{"react":"19.2.8","react-dom":"19.2.8","lucide-react":"^0.577.0"},"devDependencies":{"@types/react":"^19.2.0","@types/react-dom":"^19.2.0","@vitejs/plugin-react":"6.1.1","typescript":"~5.9.3","vite":"8.2.2"}}
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
import {useEffect,useState} from 'react';
|
import {useEffect,useState} from 'react';
|
||||||
import {api,type Hotel,type Knowledge} from './api';
|
import {api,type Hotel,type Knowledge} from './api';
|
||||||
|
import {hotelTime} from './time';
|
||||||
type Rule={id:string;question:string;knowledgeId:string;knowledgeVersion:number;enabled:boolean;version:number};
|
type Rule={id:string;question:string;knowledgeId:string;knowledgeVersion:number;enabled:boolean;version:number};
|
||||||
type Status={liveConfigured:boolean;preview:boolean;questions:string[];dailyLimit:number};
|
type Status={liveConfigured:boolean;preview:boolean;questions:string[];dailyLimit:number};
|
||||||
type Decision={matches:boolean;reason:string;body:string};
|
type Decision={matches:boolean;reason:string;body:string};
|
||||||
|
type Evaluation={total:number;passed:number;falsePositives:number;falseNegatives:number;results:{id:string;passed:boolean;reason:string}[]};
|
||||||
type History={id:string;subject:string;from:string;autoReplyCheckedAt:string;autoReplyMatched:boolean;autoReplyDetail:string;delivery:string|null};
|
type History={id:string;subject:string;from:string;autoReplyCheckedAt:string;autoReplyMatched:boolean;autoReplyDetail:string;delivery:string|null};
|
||||||
type Props={hotel:Hotel;owner:boolean;busy:boolean;run:(f:()=>Promise<void>)=>Promise<void>;onHotel:(h:Hotel)=>void};
|
type Props={hotel:Hotel;owner:boolean;busy:boolean;run:(f:()=>Promise<void>)=>Promise<void>;onHotel:(h:Hotel)=>void};
|
||||||
export function AutomationPage({hotel,owner,busy,run,onHotel}:Props){
|
export function AutomationPage({hotel,owner,busy,run,onHotel}:Props){
|
||||||
const [status,setStatus]=useState<Status|null>(null),[rules,setRules]=useState<Rule[]>([]),[knowledge,setKnowledge]=useState<Knowledge[]>([]),[history,setHistory]=useState<History[]>([]);
|
const [status,setStatus]=useState<Status|null>(null),[rules,setRules]=useState<Rule[]>([]),[knowledge,setKnowledge]=useState<Knowledge[]>([]),[history,setHistory]=useState<History[]>([]);
|
||||||
const [question,setQuestion]=useState(0),[answer,setAnswer]=useState(''),[enabled,setEnabled]=useState(false),[subject,setSubject]=useState('Parking question'),[body,setBody]=useState('Is parking available?'),[result,setResult]=useState<Decision|null>(null);
|
const [question,setQuestion]=useState(0),[answer,setAnswer]=useState(''),[enabled,setEnabled]=useState(false),[subject,setSubject]=useState('Parking question'),[body,setBody]=useState('Is parking available?'),[result,setResult]=useState<Decision|null>(null);
|
||||||
|
const [evaluationText,setEvaluationText]=useState('[\n {"id":"parking-exact","subject":"Parking","body":"Is parking available?","expectedMatch":true},\n {"id":"parking-extra-request","subject":"Parking","body":"Is parking available? Also cancel my booking.","expectedMatch":false}\n]'),[evaluation,setEvaluation]=useState<Evaluation|null>(null);
|
||||||
async function refresh(){const [s,r,k,h]=await Promise.all([api<Status>('/auto-replies/status'),api<Rule[]>('/auto-replies/rules'),api<Knowledge[]>('/knowledge'),api<History[]>('/auto-replies/history')]);setStatus(s);setRules(r);setKnowledge(k);setHistory(h);}
|
async function refresh(){const [s,r,k,h]=await Promise.all([api<Status>('/auto-replies/status'),api<Rule[]>('/auto-replies/rules'),api<Knowledge[]>('/knowledge'),api<History[]>('/auto-replies/history')]);setStatus(s);setRules(r);setKnowledge(k);setHistory(h);}
|
||||||
useEffect(()=>{run(refresh);},[hotel.id]);
|
useEffect(()=>{run(refresh);},[hotel.id]);
|
||||||
const current=rules.find(r=>r.question===status?.questions[question]);
|
const current=rules.find(r=>r.question===status?.questions[question]);
|
||||||
@@ -18,6 +21,7 @@ export function AutomationPage({hotel,owner,busy,run,onHotel}:Props){
|
|||||||
<section className="settings-card"><h2>Automation mode: {hotel.autoReplyMode||'Off'}</h2><p>Only exact, complete FAQ questions qualify. Extra requests, attachments and conversations already in progress stay with your team.</p><div className="form-actions"><button className="button secondary" disabled={busy||!owner} onClick={()=>mode('Off')}>Turn off</button><button className="button secondary" disabled={busy||!owner} onClick={()=>mode('Test')}>Use test mode</button><button className="button primary" disabled={busy||!owner||!status?.liveConfigured||!hotel.staffSendingEnabled} onClick={()=>mode('Live')}>Enable live replies</button></div><p className="small muted">Test mode sends nothing. Live mode requires administrator enablement and Gmail sending. Each mode change starts with new incoming messages; existing inbox messages are not sent automatically.</p><p className="small muted">Maximum 20 automatic replies per hotel per UTC day, one per sender per UTC day, and one per Gmail thread. Turning off stops queued replies when the worker next checks them; a request already submitted to Gmail cannot be recalled.</p>{status?.preview&&<p className="staff-note">Sample workspace: the question tester works here. Live sending is disabled.</p>}</section>
|
<section className="settings-card"><h2>Automation mode: {hotel.autoReplyMode||'Off'}</h2><p>Only exact, complete FAQ questions qualify. Extra requests, attachments and conversations already in progress stay with your team.</p><div className="form-actions"><button className="button secondary" disabled={busy||!owner} onClick={()=>mode('Off')}>Turn off</button><button className="button secondary" disabled={busy||!owner} onClick={()=>mode('Test')}>Use test mode</button><button className="button primary" disabled={busy||!owner||!status?.liveConfigured||!hotel.staffSendingEnabled} onClick={()=>mode('Live')}>Enable live replies</button></div><p className="small muted">Test mode sends nothing. Live mode requires administrator enablement and Gmail sending. Each mode change starts with new incoming messages; existing inbox messages are not sent automatically.</p><p className="small muted">Maximum 20 automatic replies per hotel per UTC day, one per sender per UTC day, and one per Gmail thread. Turning off stops queued replies when the worker next checks them; a request already submitted to Gmail cannot be recalled.</p>{status?.preview&&<p className="staff-note">Sample workspace: the question tester works here. Live sending is disabled.</p>}</section>
|
||||||
<div className="pms-columns"><section className="settings-card"><h2>Review a FAQ rule</h2><form onSubmit={save}><fieldset disabled={busy||!owner}><label>Complete guest question<select value={question} onChange={e=>setQuestion(Number(e.target.value))}>{status?.questions.map((q,i)=><option value={i} key={q}>{q}</option>)}</select></label><label>Approved hotel answer<select value={answer} required onChange={e=>setAnswer(e.target.value)}><option value="">Choose an answer</option>{knowledge.filter(k=>k.approved).map(k=><option value={k.id} key={k.id}>{k.title}</option>)}</select></label>{answer&&<p className="staff-note">{knowledge.find(k=>k.id===answer)?.answer}</p>}<label className="checkbox-label"><input type="checkbox" checked={enabled} onChange={e=>setEnabled(e.target.checked)}/>Enable this exact question and reviewed answer</label><button className="button secondary">Save reviewed rule</button></fieldset></form><p className="small muted">The approved answer is sent exactly as saved, with the hotel signature. Editing the answer pauses matching until this rule is reviewed and saved again.</p></section>
|
<div className="pms-columns"><section className="settings-card"><h2>Review a FAQ rule</h2><form onSubmit={save}><fieldset disabled={busy||!owner}><label>Complete guest question<select value={question} onChange={e=>setQuestion(Number(e.target.value))}>{status?.questions.map((q,i)=><option value={i} key={q}>{q}</option>)}</select></label><label>Approved hotel answer<select value={answer} required onChange={e=>setAnswer(e.target.value)}><option value="">Choose an answer</option>{knowledge.filter(k=>k.approved).map(k=><option value={k.id} key={k.id}>{k.title}</option>)}</select></label>{answer&&<p className="staff-note">{knowledge.find(k=>k.id===answer)?.answer}</p>}<label className="checkbox-label"><input type="checkbox" checked={enabled} onChange={e=>setEnabled(e.target.checked)}/>Enable this exact question and reviewed answer</label><button className="button secondary">Save reviewed rule</button></fieldset></form><p className="small muted">The approved answer is sent exactly as saved, with the hotel signature. Editing the answer pauses matching until this rule is reviewed and saved again.</p></section>
|
||||||
<section className="settings-card"><h2>Try a question</h2><form onSubmit={e=>{e.preventDefault();run(async()=>setResult(await api<Decision>('/auto-replies/test','POST',{subject,body})));}}><fieldset disabled={busy||!owner}><label>Subject<input value={subject} maxLength={200} onChange={e=>setSubject(e.target.value)}/></label><label>Complete message<textarea rows={4} value={body} maxLength={2000} required onChange={e=>setBody(e.target.value)}/></label><button className="button secondary">Check match without sending</button></fieldset></form>{result&&<div role="status" className="staff-note"><strong>{result.matches?'Content matches a reviewed rule':'Keep with staff'}</strong><p>{result.reason}</p>{result.body&&<p>{result.body}</p>}</div>}<p className="small muted">This tester checks content only. Real messages must also pass sender, recipient, age, thread and delivery-limit checks.</p></section></div>
|
<section className="settings-card"><h2>Try a question</h2><form onSubmit={e=>{e.preventDefault();run(async()=>setResult(await api<Decision>('/auto-replies/test','POST',{subject,body})));}}><fieldset disabled={busy||!owner}><label>Subject<input value={subject} maxLength={200} onChange={e=>setSubject(e.target.value)}/></label><label>Complete message<textarea rows={4} value={body} maxLength={2000} required onChange={e=>setBody(e.target.value)}/></label><button className="button secondary">Check match without sending</button></fieldset></form>{result&&<div role="status" className="staff-note"><strong>{result.matches?'Content matches a reviewed rule':'Keep with staff'}</strong><p>{result.reason}</p>{result.body&&<p>{result.body}</p>}</div>}<p className="small muted">This tester checks content only. Real messages must also pass sender, recipient, age, thread and delivery-limit checks.</p></section></div>
|
||||||
<section className="settings-card"><h2>Recent incoming-message results</h2>{history.length===0?<p>No incoming messages have been evaluated yet. Enable test mode after connecting your mailbox.</p>:<div className="pms-history">{history.map(h=><div className="pms-history-item" key={h.id}><strong>{h.subject}</strong><span>{h.autoReplyDetail}</span><span>{h.delivery?`Delivery: ${h.delivery} · `:''}{new Date(h.autoReplyCheckedAt).toLocaleString()}</span></div>)}</div>}</section>
|
<section className="settings-card"><h2>Recent incoming-message results</h2>{history.length===0?<p>No incoming messages have been evaluated yet. Enable test mode after connecting your mailbox.</p>:<div className="pms-history">{history.map(h=><div className="pms-history-item" key={h.id}><strong>{h.subject}</strong><span>{h.autoReplyDetail}</span><span>{h.delivery?`Delivery: ${h.delivery} · `:''}{hotelTime(h.autoReplyCheckedAt,hotel.timezone)}</span></div>)}</div>}</section>
|
||||||
|
<section className="settings-card"><h2>Batch safety evaluation</h2><p>Evaluate up to 100 synthetic cases without saving messages or sending email. Include expected matches and expected exclusions.</p><label>Evaluation cases (JSON)<textarea rows={9} value={evaluationText} onChange={e=>setEvaluationText(e.target.value)}/></label><button className="button secondary" disabled={busy||!owner} onClick={()=>run(async()=>setEvaluation(await api<Evaluation>('/auto-replies/evaluate','POST',{cases:JSON.parse(evaluationText)})))}>Run no-send evaluation</button>{evaluation&&<div className="staff-note" role="status"><strong>{evaluation.passed} of {evaluation.total} cases passed</strong><p>False positives: {evaluation.falsePositives} · False negatives: {evaluation.falseNegatives}</p>{evaluation.results.filter(r=>!r.passed).map(r=><p key={r.id}><strong>{r.id}:</strong> {r.reason}</p>)}</div>}<p className="small muted">Use synthetic content only. A passing content evaluation does not test Gmail headers, quotas, threading or delivery.</p></section>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Mail, RefreshCw, ShieldCheck } from 'lucide-react';
|
import { Mail, RefreshCw, ShieldCheck } from 'lucide-react';
|
||||||
import { api, type Mailboxes } from './api';
|
import { api, type Mailboxes } from './api';
|
||||||
|
import {hotelTime} from './time';
|
||||||
type Run=(action:()=>Promise<void>)=>Promise<void>;
|
type Run=(action:()=>Promise<void>)=>Promise<void>;
|
||||||
const when=(value:string|null)=>value?new Date(value).toLocaleString():'Not yet';
|
|
||||||
export function MailboxPanel({data,owner,preview,busy,run,onChange}:{data:Mailboxes;owner:boolean;preview:boolean;busy:boolean;run:Run;onChange:(value:Mailboxes)=>void}){
|
export function MailboxPanel({data,owner,preview,busy,run,onChange}:{data:Mailboxes;owner:boolean;preview:boolean;busy:boolean;run:Run;onChange:(value:Mailboxes)=>void}){
|
||||||
|
const when=(value:string|null)=>value?hotelTime(value,data.timeZone||'UTC'):'Not yet';
|
||||||
const [pollError,setPollError]=useState('');
|
const [pollError,setPollError]=useState('');
|
||||||
async function refresh(){onChange(await api<Mailboxes>('/mailboxes'));setPollError('');}
|
async function refresh(){onChange(await api<Mailboxes>('/mailboxes'));setPollError('');}
|
||||||
useEffect(()=>{let active=true;const timer=setInterval(()=>{if(document.hidden)return;api<Mailboxes>('/mailboxes').then(value=>{if(active){onChange(value);setPollError('');}}).catch(()=>{if(active)setPollError('Status could not be refreshed. Use Refresh status to check again.');});},30000);return()=>{active=false;clearInterval(timer);};},[onChange]);
|
useEffect(()=>{let active=true;const timer=setInterval(()=>{if(document.hidden)return;api<Mailboxes>('/mailboxes').then(value=>{if(active){onChange(value);setPollError('');}}).catch(()=>{if(active)setPollError('Status could not be refreshed. Use Refresh status to check again.');});},30000);return()=>{active=false;clearInterval(timer);};},[onChange]);
|
||||||
|
|||||||
@@ -1,10 +1,29 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import {useEffect,useState} from 'react';
|
||||||
import { api } from './api';
|
import {api} from './api';
|
||||||
type Health={checkedAt:string;preview:boolean;database:string;worker:{state:string;lastSeenAt:string|null};mailboxes:{total:number;connected:number;attention:number};replies:{sampleSize:number;sampleLimit:number;pending:number;uncertain:number;rejected:number}};
|
import {hotelTime} from './time';
|
||||||
|
|
||||||
|
type Health={
|
||||||
|
checkedAt:string;timeZone:string;preview:boolean;database:string;
|
||||||
|
worker:{state:string;lastSeenAt:string|null};
|
||||||
|
mailboxes:{total:number;connected:number;attention:number};
|
||||||
|
replies:{sampleSize:number;sampleLimit:number;pending:number;uncertain:number;rejected:number};
|
||||||
|
};
|
||||||
|
|
||||||
export function OperationsPage({owner,go}:{owner:boolean;go:(path:string)=>void}){
|
export function OperationsPage({owner,go}:{owner:boolean;go:(path:string)=>void}){
|
||||||
const [data,setData]=useState<Health|null>(null),[error,setError]=useState(''),[busy,setBusy]=useState(false);
|
const [data,setData]=useState<Health|null>(null),[error,setError]=useState(''),[busy,setBusy]=useState(false);
|
||||||
async function refresh(){setBusy(true);setError('');try{setData(await api<Health>('/operations'));}catch(e){setError(e instanceof Error?e.message:'Unable to check workspace health.');}finally{setBusy(false);}}
|
async function refresh(){setBusy(true);setError('');try{setData(await api<Health>('/operations'));}catch(e){setError(e instanceof Error?e.message:'Unable to check workspace health.');}finally{setBusy(false);}}
|
||||||
useEffect(()=>{if(owner)void refresh();},[owner]);
|
useEffect(()=>{if(owner)void refresh();},[owner]);
|
||||||
if(!owner)return <div className="page"><h1>Workspace health</h1><p>Your hotel owner can review operational health.</p></div>;
|
if(!owner)return <div className="page"><h1>Workspace health</h1><p>Your hotel owner can review operational health.</p></div>;
|
||||||
return <div className="page settings-page"><div className="heading-row"><div className="page-heading"><span className="eyebrow">Keep your workspace running</span><h1>Workspace health</h1><p>Spot connection and delivery issues before they affect your team.</p></div><button className="button secondary" disabled={busy} onClick={refresh}>{busy?'Checking…':'Refresh health'}</button></div>{error&&<div className="alert" role="alert">{error} The information below may be out of date.</div>}{data&&<><p className="small muted">Checked {new Date(data.checkedAt).toLocaleString()}{data.preview?' · Sample workspace':''}</p><section className="settings-card"><h2>Application and worker</h2><div className="mailbox-health"><div><span>Database connection</span><strong>{data.preview?'Temporary preview storage':data.database}</strong></div><div><span>Background worker</span><strong>{data.worker.state==='Reporting'?'Reporting normally':data.worker.state==='Preview'?'Unavailable in preview':data.worker.state==='Stale'?'Heartbeat overdue':'No heartbeat received'}</strong></div><div><span>Last worker heartbeat</span><strong>{data.worker.lastSeenAt?new Date(data.worker.lastSeenAt).toLocaleString():'Not yet'}</strong></div></div>{['Stale','NotSeen'].includes(data.worker.state)&&<p className="mailbox-explanation">Ask your server administrator to check the worker container and its database connection. Imports and queued replies may be delayed.</p>}<p className="small muted">A heartbeat confirms the worker process can reach storage. It does not prove that Google, payment or PMS requests are succeeding.</p></section><section className="settings-card"><h2>Mailbox connections</h2><div className="mailbox-health"><div><span>Total</span><strong>{data.mailboxes.total}</strong></div><div><span>Connected</span><strong>{data.mailboxes.connected}</strong></div><div><span>Need attention</span><strong>{data.mailboxes.attention}</strong></div></div><button className="button secondary" onClick={()=>go('/settings')}>Review mailbox status</button></section><section className="settings-card"><h2>Reply delivery</h2><div className="mailbox-health"><div><span>Queued or submitting</span><strong>{data.replies.pending}</strong></div><div><span>Need verification</span><strong>{data.replies.uncertain}</strong></div><div><span>Stopped before sending</span><strong>{data.replies.rejected}</strong></div></div><p className="small muted">Based on {data.replies.sampleSize} recent conversations, up to {data.replies.sampleLimit}. Older deliveries may exist. Verify uncertain results in Gmail before taking further action.</p><div className="form-actions"><button className="button secondary" onClick={()=>go('/inbox')}>Review the inbox</button></div></section><section className="settings-card"><h2>Backups and recovery</h2><p className="muted">Your server administrator runs encrypted backups and isolated restore drills. Ask them to confirm the latest off-server backup and successful restore test.</p><p className="small muted">This page does not claim a backup exists or that the server is ready for production. Provider acceptance and recovery checks are separate.</p></section></>}</div>;
|
const when=(value:string|null)=>value?hotelTime(value,data?.timeZone||'UTC'):'Not yet';
|
||||||
|
return <div className="page settings-page">
|
||||||
|
<div className="heading-row"><div className="page-heading"><span className="eyebrow">Keep your workspace running</span><h1>Workspace health</h1><p>Spot connection and delivery issues before they affect your team.</p></div><button className="button secondary" disabled={busy} onClick={refresh}>{busy?'Checking…':'Refresh health'}</button></div>
|
||||||
|
{error&&<div className="alert" role="alert">{error} The information below may be out of date.</div>}
|
||||||
|
{data&&<>
|
||||||
|
<p className="small muted">Checked {when(data.checkedAt)}{data.preview?' · Sample workspace':''}</p>
|
||||||
|
<section className="settings-card"><h2>Application and worker</h2><div className="mailbox-health"><div><span>Database connection</span><strong>{data.preview?'Temporary preview storage':data.database}</strong></div><div><span>Background worker</span><strong>{data.worker.state==='Reporting'?'Reporting normally':data.worker.state==='Preview'?'Unavailable in preview':data.worker.state==='Stale'?'Heartbeat overdue':'No heartbeat received'}</strong></div><div><span>Last worker heartbeat</span><strong>{when(data.worker.lastSeenAt)}</strong></div></div>{['Stale','NotSeen'].includes(data.worker.state)&&<p className="mailbox-explanation">Ask your server administrator to check the worker service and its database connection. Imports and queued replies may be delayed.</p>}<p className="small muted">A heartbeat confirms the worker process can reach storage. It does not prove that Google, payment or PMS requests are succeeding.</p></section>
|
||||||
|
<section className="settings-card"><h2>Mailbox connections</h2><div className="mailbox-health"><div><span>Total</span><strong>{data.mailboxes.total}</strong></div><div><span>Connected</span><strong>{data.mailboxes.connected}</strong></div><div><span>Need attention</span><strong>{data.mailboxes.attention}</strong></div></div><button className="button secondary" onClick={()=>go('/settings')}>Review mailbox status</button></section>
|
||||||
|
<section className="settings-card"><h2>Reply delivery</h2><div className="mailbox-health"><div><span>Queued or submitting</span><strong>{data.replies.pending}</strong></div><div><span>Need verification</span><strong>{data.replies.uncertain}</strong></div><div><span>Stopped before sending</span><strong>{data.replies.rejected}</strong></div></div><p className="small muted">Based on {data.replies.sampleSize} recent conversations, up to {data.replies.sampleLimit}. Older deliveries may exist. Verify uncertain results in Gmail before taking further action.</p><div className="form-actions"><button className="button secondary" onClick={()=>go('/inbox')}>Review the inbox</button></div></section>
|
||||||
|
<section className="settings-card"><h2>Backups and recovery</h2><p className="muted">Your server administrator runs encrypted backups and isolated restore drills. Ask them to confirm the latest off-server backup and successful restore test.</p><p className="small muted">This page does not claim a backup exists or that the server is ready for production. Provider acceptance and recovery checks are separate.</p></section>
|
||||||
|
</>}
|
||||||
|
</div>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { api, type Hotel } from './api';
|
import { api, type Hotel } from './api';
|
||||||
|
import { hotelTime } from './time';
|
||||||
type Payment={id:string;reference:string;email:string;description:string;amount:number;currency:string;state:string;detail:string;invoiceId:string;version:number;expiresAt:string;updatedAt:string;checkedAt:string|null};
|
type Payment={id:string;reference:string;email:string;description:string;amount:number;currency:string;state:string;detail:string;invoiceId:string;version:number;expiresAt:string;updatedAt:string;checkedAt:string|null};
|
||||||
type Connection={configured:boolean;createsConfigured:boolean;sandbox:boolean;preview:boolean};
|
type Connection={configured:boolean;createsConfigured:boolean;sandbox:boolean;preview:boolean};
|
||||||
type Props={hotel:Hotel;owner:boolean;busy:boolean;run:(f:()=>Promise<void>)=>Promise<void>;onHotel:(h:Hotel)=>void};
|
type Props={hotel:Hotel;owner:boolean;busy:boolean;run:(f:()=>Promise<void>)=>Promise<void>;onHotel:(h:Hotel)=>void};
|
||||||
@@ -19,7 +20,7 @@ export function PaymentsPage({hotel,owner,busy,run,onHotel}:Props){
|
|||||||
<section className="settings-card"><h2>Payment connection</h2><p>{connection?.preview?'Sample workspace: no invoices, emails or payments can be created.':connection?.configured?`NMI ${connection.sandbox?'sandbox':'production'} configuration is available.`:'Your administrator needs to configure this hotel’s NMI merchant account.'}</p><p className="small muted">GuestOps hotel ID: {hotel.id}</p><label className="checkbox-label"><input type="checkbox" checked={hotel.paymentsEnabled||false} disabled={busy||!owner||(!connection?.createsConfigured&&!hotel.paymentsEnabled)} onChange={e=>{const enabled=e.target.checked;run(async()=>{if(enabled&&!window.confirm('Enable reviewed NMI invoice creation after sandbox acceptance? Creating an invoice may email the customer.'))return;onHotel(await api<Hotel>('/payments/controls','PUT',{version:hotel.version,enabled}));});}}/>Allow owner-approved payment invoices</label><p className="small muted">Card details are entered on NMI’s hosted page. GuestOps never asks for a card number.</p></section>
|
<section className="settings-card"><h2>Payment connection</h2><p>{connection?.preview?'Sample workspace: no invoices, emails or payments can be created.':connection?.configured?`NMI ${connection.sandbox?'sandbox':'production'} configuration is available.`:'Your administrator needs to configure this hotel’s NMI merchant account.'}</p><p className="small muted">GuestOps hotel ID: {hotel.id}</p><label className="checkbox-label"><input type="checkbox" checked={hotel.paymentsEnabled||false} disabled={busy||!owner||(!connection?.createsConfigured&&!hotel.paymentsEnabled)} onChange={e=>{const enabled=e.target.checked;run(async()=>{if(enabled&&!window.confirm('Enable reviewed NMI invoice creation after sandbox acceptance? Creating an invoice may email the customer.'))return;onHotel(await api<Hotel>('/payments/controls','PUT',{version:hotel.version,enabled}));});}}/>Allow owner-approved payment invoices</label><p className="small muted">Card details are entered on NMI’s hosted page. GuestOps never asks for a card number.</p></section>
|
||||||
<div className="pms-columns"><section className="settings-card"><h2>Prepare a payment request</h2><form onSubmit={propose}><fieldset disabled={busy||!owner||!connection?.configured}><label>Unique payment reference<input value={reference} onChange={e=>setReference(e.target.value)} pattern="[A-Za-z0-9-]+" maxLength={80} required placeholder="WH-2481-DEPOSIT"/></label><label>Customer email<input type="email" value={email} onChange={e=>setEmail(e.target.value)} maxLength={254} required/></label><label>Description<input value={description} onChange={e=>setDescription(e.target.value)} maxLength={250} required placeholder="Deposit for reservation WH-2481"/></label><div className="form-grid"><label>Amount<input type="number" min="0.01" max="100000" step="0.01" required value={amount} onChange={e=>setAmount(e.target.value)}/></label><label>Currency<select value={currency} onChange={e=>setCurrency(e.target.value)}><option>GBP</option><option>EUR</option><option>USD</option></select></label></div><button className="button secondary">Prepare for review</button></fieldset></form><p className="small muted">Preparation saves a proposal only. Verify the agreed amount and booking terms separately; this does not reserve a room.</p></section>
|
<div className="pms-columns"><section className="settings-card"><h2>Prepare a payment request</h2><form onSubmit={propose}><fieldset disabled={busy||!owner||!connection?.configured}><label>Unique payment reference<input value={reference} onChange={e=>setReference(e.target.value)} pattern="[A-Za-z0-9-]+" maxLength={80} required placeholder="WH-2481-DEPOSIT"/></label><label>Customer email<input type="email" value={email} onChange={e=>setEmail(e.target.value)} maxLength={254} required/></label><label>Description<input value={description} onChange={e=>setDescription(e.target.value)} maxLength={250} required placeholder="Deposit for reservation WH-2481"/></label><div className="form-grid"><label>Amount<input type="number" min="0.01" max="100000" step="0.01" required value={amount} onChange={e=>setAmount(e.target.value)}/></label><label>Currency<select value={currency} onChange={e=>setCurrency(e.target.value)}><option>GBP</option><option>EUR</option><option>USD</option></select></label></div><button className="button secondary">Prepare for review</button></fieldset></form><p className="small muted">Preparation saves a proposal only. Verify the agreed amount and booking terms separately; this does not reserve a room.</p></section>
|
||||||
<section className="settings-card"><h2>Payment history</h2>{items.length===0&&<p>No payment requests yet.</p>}<div className="pms-history">{items.map(p=><button key={p.id} className={'pms-history-item '+(selected===p.id?'selected':'')} onClick={()=>{setSelected(p.id);setApproved(false);}}><strong>{p.reference} · {p.currency} {p.amount.toFixed(2)}</strong><span>{p.state==='NeedsReview'?'Needs verification':p.state==='Paid'?'Paid · reported by NMI':p.state} · {p.email}</span></button>)}</div></section></div>
|
<section className="settings-card"><h2>Payment history</h2>{items.length===0&&<p>No payment requests yet.</p>}<div className="pms-history">{items.map(p=><button key={p.id} className={'pms-history-item '+(selected===p.id?'selected':'')} onClick={()=>{setSelected(p.id);setApproved(false);}}><strong>{p.reference} · {p.currency} {p.amount.toFixed(2)}</strong><span>{p.state==='NeedsReview'?'Needs verification':p.state==='Paid'?'Paid · reported by NMI':p.state} · {p.email}</span></button>)}</div></section></div>
|
||||||
{current&&<section className="settings-card" aria-label="Payment request review"><h2>{current.state==='Review'?'Review this payment request':'Payment request status'}</h2><dl className="pms-reservation"><div><dt>Reference</dt><dd>{current.reference}</dd></div><div><dt>Customer</dt><dd>{current.email}</dd></div><div><dt>Amount</dt><dd>{current.currency} {current.amount.toFixed(2)}</dd></div><div><dt>Description</dt><dd>{current.description}</dd></div><div><dt>NMI invoice</dt><dd>{current.invoiceId||'Not confirmed'}</dd></div><div><dt>Last verified</dt><dd>{current.checkedAt?new Date(current.checkedAt).toLocaleString():'Not yet verified'}</dd></div></dl><p role="status"><strong>{current.state==='Paid'?'Paid · reported by NMI':current.state}</strong> — {current.detail}</p>
|
{current&&<section className="settings-card" aria-label="Payment request review"><h2>{current.state==='Review'?'Review this payment request':'Payment request status'}</h2><dl className="pms-reservation"><div><dt>Reference</dt><dd>{current.reference}</dd></div><div><dt>Customer</dt><dd>{current.email}</dd></div><div><dt>Amount</dt><dd>{current.currency} {current.amount.toFixed(2)}</dd></div><div><dt>Description</dt><dd>{current.description}</dd></div><div><dt>NMI invoice</dt><dd>{current.invoiceId||'Not confirmed'}</dd></div><div><dt>Last verified</dt><dd>{current.checkedAt?hotelTime(current.checkedAt,hotel.timezone):'Not yet verified'}</dd></div></dl><p role="status"><strong>{current.state==='Paid'?'Paid · reported by NMI':current.state}</strong> — {current.detail}</p>
|
||||||
{current.state==='Review'?<><div className="staff-note">Creating the invoice may email this customer a hosted payment link through NMI. GuestOps records the invoice and its status.</div><label className="checkbox-label"><input type="checkbox" checked={approved} onChange={e=>setApproved(e.target.checked)}/>I checked the recipient, amount and currency, and approve NMI emailing this payment request.</label><div className="form-actions"><button className="button secondary" disabled={busy||!owner||connection?.preview} onClick={()=>action('cancel')}>Cancel proposal</button><button className="button primary" disabled={busy||!owner||connection?.preview||!hotel.paymentsEnabled||!connection?.createsConfigured||!approved||Date.now()>new Date(current.expiresAt).getTime()} onClick={()=>action('create')}>Approve and create invoice</button></div><p className="small muted">Approval expires after fifteen minutes. A payment reference cannot be reused.</p></>:!['Cancelled','NotCreated'].includes(current.state)&&<><button className="button secondary" disabled={busy||!owner||connection?.preview||(current.state==='Creating'&&Date.now()-new Date(current.updatedAt).getTime()<300000)} onClick={()=>action('check')}>Verify with NMI</button><p className="small muted">This only reads invoice status. An interrupted creation can be checked after five minutes. Uncertain invoices are never automatically recreated.</p></>}
|
{current.state==='Review'?<><div className="staff-note">Creating the invoice may email this customer a hosted payment link through NMI. GuestOps records the invoice and its status.</div><label className="checkbox-label"><input type="checkbox" checked={approved} onChange={e=>setApproved(e.target.checked)}/>I checked the recipient, amount and currency, and approve NMI emailing this payment request.</label><div className="form-actions"><button className="button secondary" disabled={busy||!owner||connection?.preview} onClick={()=>action('cancel')}>Cancel proposal</button><button className="button primary" disabled={busy||!owner||connection?.preview||!hotel.paymentsEnabled||!connection?.createsConfigured||!approved||Date.now()>new Date(current.expiresAt).getTime()} onClick={()=>action('create')}>Approve and create invoice</button></div><p className="small muted">Approval expires after fifteen minutes. A payment reference cannot be reused.</p></>:!['Cancelled','NotCreated'].includes(current.state)&&<><button className="button secondary" disabled={busy||!owner||connection?.preview||(current.state==='Creating'&&Date.now()-new Date(current.updatedAt).getTime()<300000)} onClick={()=>action('check')}>Verify with NMI</button><p className="small muted">This only reads invoice status. An interrupted creation can be checked after five minutes. Uncertain invoices are never automatically recreated.</p></>}
|
||||||
<p className="small muted">A paid invoice is not confirmation of bank settlement or a hotel booking. Refunds, invoice closure and disputes are handled in the merchant portal.</p>
|
<p className="small muted">A paid invoice is not confirmation of bank settlement or a hotel booking. Refunds, invoice closure and disputes are handled in the merchant portal.</p>
|
||||||
</section>}
|
</section>}
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { api, type Hotel } from './api';
|
import { api, type Hotel } from './api';
|
||||||
|
import { hotelTime } from './time';
|
||||||
type Snapshot={id:string;reservationId:string;confirmation:string;guestName:string;arrival:string;departure:string;status:string;roomType:string;total:string;fetchedAt:string};
|
type Snapshot={id:string;reservationId:string;confirmation:string;guestName:string;arrival:string;departure:string;status:string;roomType:string;total:string;fetchedAt:string};
|
||||||
type Change={id:string;reservationId:string;kind:string;arrival:string;departure:string;note:string;state:string;detail:string;version:number;updatedAt:string;expiresAt:string;before:Snapshot;after:Snapshot|null};
|
type Change={id:string;reservationId:string;kind:string;arrival:string;departure:string;note:string;state:string;detail:string;version:number;updatedAt:string;expiresAt:string;before:Snapshot;after:Snapshot|null};
|
||||||
type Connection={configured:boolean;writesConfigured:boolean;hotelCode:string;preview:boolean};
|
type Connection={configured:boolean;writesConfigured:boolean;hotelCode:string;preview:boolean};
|
||||||
@@ -21,7 +22,7 @@ export function PmsPage({hotel,owner,busy,run,onHotel}:Props){
|
|||||||
<section className="settings-card"><h2>OHIP connection</h2><p>{connection?.configured?`Connected configuration for property ${connection.hotelCode}. Lookup will verify access.`:connection?.preview?'Sample workspace: real PMS lookup and updates are disabled.':'Your administrator needs to configure this hotel’s OHIP connection.'}</p><p className="small muted">GuestOps hotel ID: {hotel.id}</p><label className="checkbox-label"><input type="checkbox" checked={hotel.pmsUpdatesEnabled||false} disabled={busy||!owner||(!connection?.writesConfigured&&!hotel.pmsUpdatesEnabled)} onChange={e=>{const enabled=e.target.checked;run(async()=>{if(enabled&&!window.confirm('Enable staff-approved PMS updates for this hotel? Only enable this after the configured OHIP sandbox has passed acceptance checks.'))return;onHotel(await api<Hotel>('/pms/controls','PUT',{version:hotel.version,enabled}));});}}/>Allow owner-approved PMS updates</label><p className="small muted">Lookup is available separately. Every change needs review; automatic PMS updates are off.</p></section>
|
<section className="settings-card"><h2>OHIP connection</h2><p>{connection?.configured?`Connected configuration for property ${connection.hotelCode}. Lookup will verify access.`:connection?.preview?'Sample workspace: real PMS lookup and updates are disabled.':'Your administrator needs to configure this hotel’s OHIP connection.'}</p><p className="small muted">GuestOps hotel ID: {hotel.id}</p><label className="checkbox-label"><input type="checkbox" checked={hotel.pmsUpdatesEnabled||false} disabled={busy||!owner||(!connection?.writesConfigured&&!hotel.pmsUpdatesEnabled)} onChange={e=>{const enabled=e.target.checked;run(async()=>{if(enabled&&!window.confirm('Enable staff-approved PMS updates for this hotel? Only enable this after the configured OHIP sandbox has passed acceptance checks.'))return;onHotel(await api<Hotel>('/pms/controls','PUT',{version:hotel.version,enabled}));});}}/>Allow owner-approved PMS updates</label><p className="small muted">Lookup is available separately. Every change needs review; automatic PMS updates are off.</p></section>
|
||||||
<div className="pms-columns"><section className="settings-card"><h2>Find a reservation</h2><form onSubmit={lookup}><label>Exact confirmation number<input value={confirmation} maxLength={80} pattern="[a-zA-Z0-9-]+" required onChange={e=>setConfirmation(e.target.value)} placeholder="For example, 12345678"/></label><button className="button primary" disabled={busy||!connection?.configured}>Look up reservation</button></form>
|
<div className="pms-columns"><section className="settings-card"><h2>Find a reservation</h2><form onSubmit={lookup}><label>Exact confirmation number<input value={confirmation} maxLength={80} pattern="[a-zA-Z0-9-]+" required onChange={e=>setConfirmation(e.target.value)} placeholder="For example, 12345678"/></label><button className="button primary" disabled={busy||!connection?.configured}>Look up reservation</button></form>
|
||||||
{snapshot&&<><Reservation value={snapshot}/><form onSubmit={propose}><fieldset disabled={busy||!owner}><label>Proposed action<select value={kind} onChange={e=>setKind(e.target.value)}><option value="AddNote">Add an internal reservation note</option><option value="StayDates">Change stay dates</option></select></label>{kind==='AddNote'?<label>Note<textarea rows={4} maxLength={2000} value={note} required onChange={e=>setNote(e.target.value)}/></label>:<div className="form-grid"><label>New arrival<input type="date" value={arrival} required onChange={e=>setArrival(e.target.value)}/></label><label>New departure<input type="date" value={departure} required onChange={e=>setDeparture(e.target.value)}/></label></div>}<button className="button secondary">Prepare for review</button></fieldset></form><p className="small muted">Preparing a proposal does not update the PMS. Lookup and proposals expire after ten minutes.</p></>}
|
{snapshot&&<><Reservation value={snapshot}/><form onSubmit={propose}><fieldset disabled={busy||!owner}><label>Proposed action<select value={kind} onChange={e=>setKind(e.target.value)}><option value="AddNote">Add an internal reservation note</option><option value="StayDates">Change stay dates</option></select></label>{kind==='AddNote'?<label>Note<textarea rows={4} maxLength={2000} value={note} required onChange={e=>setNote(e.target.value)}/></label>:<div className="form-grid"><label>New arrival<input type="date" value={arrival} required onChange={e=>setArrival(e.target.value)}/></label><label>New departure<input type="date" value={departure} required onChange={e=>setDeparture(e.target.value)}/></label></div>}<button className="button secondary">Prepare for review</button></fieldset></form><p className="small muted">Preparing a proposal does not update the PMS. Lookup and proposals expire after ten minutes.</p></>}
|
||||||
</section><section className="settings-card"><h2>Change history</h2>{!changes.length&&<p>No PMS changes have been prepared yet.</p>}<div className="pms-history">{changes.map(c=><button className={'pms-history-item '+(selected===c.id?'selected':'')} key={c.id} onClick={()=>{setSelected(c.id);setChecked(false);}}><strong>{c.before.confirmation} · {c.kind==='AddNote'?'Reservation note':'Stay dates'}</strong><span>{c.state==='NeedsReview'?'Needs verification':c.state} · {new Date(c.updatedAt).toLocaleString()}</span></button>)}</div></section></div>
|
</section><section className="settings-card"><h2>Change history</h2>{!changes.length&&<p>No PMS changes have been prepared yet.</p>}<div className="pms-history">{changes.map(c=><button className={'pms-history-item '+(selected===c.id?'selected':'')} key={c.id} onClick={()=>{setSelected(c.id);setChecked(false);}}><strong>{c.before.confirmation} · {c.kind==='AddNote'?'Reservation note':'Stay dates'}</strong><span>{c.state==='NeedsReview'?'Needs verification':c.state} · {hotelTime(c.updatedAt,hotel.timezone)}</span></button>)}</div></section></div>
|
||||||
{current&&<section className="settings-card pms-review" aria-label="PMS change review"><h2>{current.state==='Review'?'Review this PMS change':'PMS change status'}</h2><Reservation value={current.before}/><div className="staff-note">{current.kind==='StayDates'?`Requested stay: ${current.arrival} to ${current.departure}`:`Add internal note: ${current.note}`}</div><p role="status"><strong>{current.state==='NeedsReview'?'Needs verification':current.state}</strong> — {current.detail}</p>{current.after&&<><h3>Latest observed PMS state</h3><Reservation value={current.after}/></>}{current.state==='Review'&&<>{current.kind==='StayDates'&&<label className="checkbox-label"><input type="checkbox" checked={checked} onChange={e=>setChecked(e.target.checked)}/>I checked availability, rate consequences and guest agreement in the PMS. GuestOps does not quote or guarantee a new price here.</label>}<div className="form-actions"><button className="button secondary" disabled={busy||!owner||connection?.preview} onClick={()=>action('cancel')}>Cancel proposal</button><button className="button primary" disabled={busy||!owner||!hotel.pmsUpdatesEnabled||!connection?.writesConfigured||(current.kind==='StayDates'&&!checked)||new Date(current.expiresAt)<new Date()} onClick={()=>action('apply')}>Approve and apply to PMS</button></div></>}{(current.state==='NeedsReview'||current.state==='Applying')&&<><button className="button secondary" disabled={busy||!owner||(current.state==='Applying'&&Date.now()-new Date(current.updatedAt).getTime()<300000)} onClick={()=>action('verify')}>Verify current PMS state</button><p className="small muted">An interrupted update can be checked after five minutes. Verification only reads the PMS; it never repeats the update.</p></>}<p className="small muted">Operation reference: {current.id}</p></section>}
|
{current&&<section className="settings-card pms-review" aria-label="PMS change review"><h2>{current.state==='Review'?'Review this PMS change':'PMS change status'}</h2><Reservation value={current.before}/><div className="staff-note">{current.kind==='StayDates'?`Requested stay: ${current.arrival} to ${current.departure}`:`Add internal note: ${current.note}`}</div><p role="status"><strong>{current.state==='NeedsReview'?'Needs verification':current.state}</strong> — {current.detail}</p>{current.after&&<><h3>Latest observed PMS state</h3><Reservation value={current.after}/></>}{current.state==='Review'&&<>{current.kind==='StayDates'&&<label className="checkbox-label"><input type="checkbox" checked={checked} onChange={e=>setChecked(e.target.checked)}/>I checked availability, rate consequences and guest agreement in the PMS. GuestOps does not quote or guarantee a new price here.</label>}<div className="form-actions"><button className="button secondary" disabled={busy||!owner||connection?.preview} onClick={()=>action('cancel')}>Cancel proposal</button><button className="button primary" disabled={busy||!owner||!hotel.pmsUpdatesEnabled||!connection?.writesConfigured||(current.kind==='StayDates'&&!checked)||new Date(current.expiresAt)<new Date()} onClick={()=>action('apply')}>Approve and apply to PMS</button></div></>}{(current.state==='NeedsReview'||current.state==='Applying')&&<><button className="button secondary" disabled={busy||!owner||(current.state==='Applying'&&Date.now()-new Date(current.updatedAt).getTime()<300000)} onClick={()=>action('verify')}>Verify current PMS state</button><p className="small muted">An interrupted update can be checked after five minutes. Verification only reads the PMS; it never repeats the update.</p></>}<p className="small muted">Operation reference: {current.id}</p></section>}
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { api } from './api';
|
import { api } from './api';
|
||||||
|
import { hotelTime } from './time';
|
||||||
type Member={id:string;name:string;email:string;role:string;active:boolean;pending:boolean;version:number;linkPurpose:string;linkExpiresAt:string|null};
|
type Member={id:string;name:string;email:string;role:string;active:boolean;pending:boolean;version:number;linkPurpose:string;linkExpiresAt:string|null};
|
||||||
type Link={userId:string;link:string;expiresAt:string};
|
type Link={userId:string;link:string;expiresAt:string};
|
||||||
export function TeamPage({owner}:{owner:boolean}) {
|
export function TeamPage({owner,timeZone}:{owner:boolean;timeZone:string}) {
|
||||||
const [members,setMembers]=useState<Member[]>([]),[name,setName]=useState(''),[email,setEmail]=useState(''),[error,setError]=useState(''),[busy,setBusy]=useState(false),[link,setLink]=useState<Link|null>(null),[copied,setCopied]=useState(false);
|
const [members,setMembers]=useState<Member[]>([]),[name,setName]=useState(''),[email,setEmail]=useState(''),[error,setError]=useState(''),[busy,setBusy]=useState(false),[link,setLink]=useState<Link|null>(null),[copied,setCopied]=useState(false);
|
||||||
async function refresh(){setMembers(await api<Member[]>('/team'));}
|
async function refresh(){setMembers(await api<Member[]>('/team'));}
|
||||||
useEffect(()=>{if(owner)refresh().catch(e=>setError(e.message));},[owner]);
|
useEffect(()=>{if(owner)refresh().catch(e=>setError(e.message));},[owner]);
|
||||||
async function act(path:string,body:unknown){if(busy)return;setBusy(true);setError('');setLink(null);setCopied(false);try{const result=await api<Link|null>(path,'POST',body);if(result?.link)setLink(result);await refresh();}catch(e){setError(e instanceof Error?e.message:'Please try again.');}finally{setBusy(false);}}
|
async function act(path:string,body:unknown){if(busy)return;setBusy(true);setError('');setLink(null);setCopied(false);try{const result=await api<Link|null>(path,'POST',body);if(result?.link)setLink(result);await refresh();}catch(e){setError(e instanceof Error?e.message:'Please try again.');}finally{setBusy(false);}}
|
||||||
if(!owner)return <div className="page"><h1>Team access</h1><p>Your hotel owner manages staff accounts.</p></div>;
|
if(!owner)return <div className="page"><h1>Team access</h1><p>Your hotel owner manages staff accounts.</p></div>;
|
||||||
return <div className="page settings-page"><div className="page-heading"><span className="eyebrow">A place for everyone</span><h1>Your team</h1><p>Give each colleague their own access to the hotel workspace.</p></div>{error&&<div className="alert" role="alert">{error}</div>}
|
return <div className="page settings-page"><div className="page-heading"><span className="eyebrow">A place for everyone</span><h1>Your team</h1><p>Give each colleague their own access to the hotel workspace.</p></div>{error&&<div className="alert" role="alert">{error}</div>}
|
||||||
{link&&<section className="settings-card account-link" aria-label="Private account link"><h2>Share this link privately</h2><p><strong>For {members.find(m=>m.id===link.userId)?.email||"the selected colleague"}</strong></p><p>No email has been sent. Verify the colleague's identity and share only with the intended account holder. Anyone with this link can set their password.</p><p>Expires {new Date(link.expiresAt).toLocaleString()}. The link is shown here once.</p><label>Private account link<textarea readOnly rows={3} value={link.link} onFocus={e=>e.target.select()}/></label><div className="form-actions"><button className="button secondary" onClick={()=>setLink(null)}>Dismiss link</button><button className="button primary" onClick={async()=>{try{await navigator.clipboard.writeText(link.link);setCopied(true);}catch{setError('Select and copy the link manually.');}}}>{copied?'Copied':'Copy private link'}</button></div></section>}
|
{link&&<section className="settings-card account-link" aria-label="Private account link"><h2>Share this link privately</h2><p><strong>For {members.find(m=>m.id===link.userId)?.email||"the selected colleague"}</strong></p><p>No email has been sent. Verify the colleague's identity and share only with the intended account holder. Anyone with this link can set their password.</p><p>Expires {hotelTime(link.expiresAt,timeZone)}. The link is shown here once.</p><label>Private account link<textarea readOnly rows={3} value={link.link} onFocus={e=>e.target.select()}/></label><div className="form-actions"><button className="button secondary" onClick={()=>setLink(null)}>Dismiss link</button><button className="button primary" onClick={async()=>{try{await navigator.clipboard.writeText(link.link);setCopied(true);}catch{setError('Select and copy the link manually.');}}}>{copied?'Copied':'Copy private link'}</button></div></section>}
|
||||||
<section className="settings-card"><h2>Invite a colleague</h2><p className="muted">Staff can work on guest conversations. Owners manage hotel settings, integrations and approvals.</p><form onSubmit={e=>{e.preventDefault();void act('/team/invite',{name,email});}}><fieldset disabled={busy}><div className="form-grid"><label>Full name<input required minLength={2} maxLength={100} value={name} onChange={e=>setName(e.target.value)}/></label><label>Work email<input type="email" required maxLength={254} value={email} onChange={e=>setEmail(e.target.value)}/></label></div><div className="form-actions"><button className="button primary">Create invitation link</button></div></fieldset></form></section>
|
<section className="settings-card"><h2>Invite a colleague</h2><p className="muted">Staff can work on guest conversations. Owners manage hotel settings, integrations and approvals.</p><form onSubmit={e=>{e.preventDefault();void act('/team/invite',{name,email});}}><fieldset disabled={busy}><div className="form-grid"><label>Full name<input required minLength={2} maxLength={100} value={name} onChange={e=>setName(e.target.value)}/></label><label>Work email<input type="email" required maxLength={254} value={email} onChange={e=>setEmail(e.target.value)}/></label></div><div className="form-actions"><button className="button primary">Create invitation link</button></div></fieldset></form></section>
|
||||||
<section className="settings-card"><h2>Workspace members</h2><div className="team-list">{members.map(m=><article className="team-member" key={m.id}><div><strong>{m.name}</strong><p>{m.email}</p><span className={'status '+(m.active?'Completed':'NeedsAttention')}>{m.role} · {m.active?'Active':m.pending?'Awaiting invitation acceptance':'Disabled'}</span>{m.linkPurpose&&<p className="small muted">{m.linkPurpose} link expires {new Date(m.linkExpiresAt!).toLocaleString()}</p>}</div>{m.role==='Staff'&&<div className="team-actions">{m.pending?<button className="button secondary compact" disabled={busy} onClick={()=>act('/team/invite',{name:m.name,email:m.email})}>New invitation</button>:<button className="button secondary compact" disabled={busy} onClick={()=>act(`/team/${m.id}/${m.active?'reset':'restore'}`,{version:m.version})}>{m.active?'Reset password':'Restore access'}</button>}{m.linkPurpose&&<button className="button secondary compact" disabled={busy} onClick={()=>act(`/team/${m.id}/revoke`,{version:m.version})}>Revoke link</button>}{m.active&&<button className="button secondary compact" disabled={busy} onClick={()=>{if(window.confirm(`Disable access for ${m.name}? Their existing sessions will end.`))void act(`/team/${m.id}/disable`,{version:m.version});}}>Disable access</button>}</div>}</article>)}</div><p className="small muted">New links replace earlier links. Password recovery ends existing sessions once accepted. Owner recovery is handled by your server administrator.</p></section>
|
<section className="settings-card"><h2>Workspace members</h2><div className="team-list">{members.map(m=><article className="team-member" key={m.id}><div><strong>{m.name}</strong><p>{m.email}</p><span className={'status '+(m.active?'Completed':'NeedsAttention')}>{m.role} · {m.active?'Active':m.pending?'Awaiting invitation acceptance':'Disabled'}</span>{m.linkPurpose&&<p className="small muted">{m.linkPurpose} link expires {hotelTime(m.linkExpiresAt!,timeZone)}</p>}</div>{m.role==='Staff'&&<div className="team-actions">{m.pending?<button className="button secondary compact" disabled={busy} onClick={()=>act('/team/invite',{name:m.name,email:m.email})}>New invitation</button>:<button className="button secondary compact" disabled={busy} onClick={()=>act(`/team/${m.id}/${m.active?'reset':'restore'}`,{version:m.version})}>{m.active?'Reset password':'Restore access'}</button>}{m.linkPurpose&&<button className="button secondary compact" disabled={busy} onClick={()=>act(`/team/${m.id}/revoke`,{version:m.version})}>Revoke link</button>}{m.active&&<button className="button secondary compact" disabled={busy} onClick={()=>{if(window.confirm(`Disable access for ${m.name}? Their existing sessions will end.`))void act(`/team/${m.id}/disable`,{version:m.version});}}>Disable access</button>}</div>}</article>)}</div><p className="small muted">New links replace earlier links. Password recovery ends existing sessions once accepted. Owner recovery is handled by your server administrator.</p></section>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
type Setup={preview:boolean;steps:{title:string;detail:string;path:string;complete:boolean;optional:boolean}[]};
|
type Setup={preview:boolean;steps:{title:string;detail:string;path:string;complete:boolean;optional:boolean}[]};
|
||||||
|
|||||||
+2
-1
@@ -2,9 +2,10 @@ export type User = { id: string; name: string; role: string; hotelId: string };
|
|||||||
export type Session = { preview: boolean; csrfToken: string; user: User | null };
|
export type Session = { preview: boolean; csrfToken: string; user: User | null };
|
||||||
export type Hotel = { id: string; name: string; timezone: string; signature: string; replyMode: string; version: number; aiDraftsEnabled: boolean; staffSendingEnabled: boolean; autoReplyMode: string; paymentsEnabled: boolean; pmsUpdatesEnabled: boolean };
|
export type Hotel = { id: string; name: string; timezone: string; signature: string; replyMode: string; version: number; aiDraftsEnabled: boolean; staffSendingEnabled: boolean; autoReplyMode: string; paymentsEnabled: boolean; pmsUpdatesEnabled: boolean };
|
||||||
export type Conversation = { id: string; from: string; subject: string; body: string; receivedAt: string; status: string; draft: string; category: string; note: string; providerThreadId: string; version: number; mailboxId: string; autoReplyDetail: string; replyAddress: string; draftSources: string[]; draftReviewNote: string; delivery: { automatic: boolean; state: string; recipient: string; body: string; detail: string; messageId: string; providerId: string } | null };
|
export type Conversation = { id: string; from: string; subject: string; body: string; receivedAt: string; status: string; draft: string; category: string; note: string; providerThreadId: string; version: number; mailboxId: string; autoReplyDetail: string; replyAddress: string; draftSources: string[]; draftReviewNote: string; delivery: { automatic: boolean; state: string; recipient: string; body: string; detail: string; messageId: string; providerId: string } | null };
|
||||||
|
export type ConversationPage = { items: Conversation[]; nextCursor: string | null };
|
||||||
export type Knowledge = { id: string; title: string; category: string; answer: string; keywords: string; approved: boolean; version: number };
|
export type Knowledge = { id: string; title: string; category: string; answer: string; keywords: string; approved: boolean; version: number };
|
||||||
export type Activity = { id: string; at: string; userName: string; action: string };
|
export type Activity = { id: string; at: string; userName: string; action: string };
|
||||||
export type Mailboxes = { configured: boolean; aiConfigured?: boolean; sendingConfigured?: boolean; items: { id: string; email: string; status: string; version: number; lastSyncAt: string | null; lastAttemptAt: string | null; nextAttemptAt: string | null; failureCount: number; syncErrorCode: string; catchingUp: boolean; syncError: string; canSend: boolean }[] };
|
export type Mailboxes = { configured: boolean; aiConfigured?: boolean; sendingConfigured?: boolean; timeZone?: string; items: { id: string; email: string; status: string; version: number; lastSyncAt: string | null; lastAttemptAt: string | null; nextAttemptAt: string | null; failureCount: number; syncErrorCode: string; catchingUp: boolean; syncError: string; canSend: boolean }[] };
|
||||||
let csrf = '';
|
let csrf = '';
|
||||||
export async function api<T>(path: string, method = 'GET', body?: unknown): Promise<T> {
|
export async function api<T>(path: string, method = 'GET', body?: unknown): Promise<T> {
|
||||||
const response = await fetch('/api' + path, { method, credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrf }, body: body === undefined ? undefined : JSON.stringify(body) });
|
const response = await fetch('/api' + path, { method, credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrf }, body: body === undefined ? undefined : JSON.stringify(body) });
|
||||||
|
|||||||
+15
-11
@@ -1,7 +1,7 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { createRoot } from 'react-dom/client';
|
import { createRoot } from 'react-dom/client';
|
||||||
import { Inbox, BookOpen, Settings, Activity as ActivityIcon, Search, ArrowUpRight, ChevronDown, Check, CheckCheck, Clock3, FileText, LogOut, RefreshCw, ArrowLeft, Plus, X, Mail, ShieldCheck, Save, CircleHelp, Banknote, Building2, ChevronRight } from 'lucide-react';
|
import { Inbox, BookOpen, Settings, Activity as ActivityIcon, Search, ArrowUpRight, ChevronDown, Check, CheckCheck, Clock3, FileText, LogOut, RefreshCw, ArrowLeft, Plus, X, Mail, ShieldCheck, Save, CircleHelp, Banknote, Building2, ChevronRight } from 'lucide-react';
|
||||||
import { api, session, type Session, type Hotel, type Conversation, type Knowledge, type Activity, type Mailboxes } from './api';
|
import { api, session, type Session, type Hotel, type Conversation, type ConversationPage, type Knowledge, type Activity, type Mailboxes } from './api';
|
||||||
import './style.css';
|
import './style.css';
|
||||||
import { OperationsPage } from './OperationsPage';
|
import { OperationsPage } from './OperationsPage';
|
||||||
import { MailboxPanel } from './MailboxPanel';
|
import { MailboxPanel } from './MailboxPanel';
|
||||||
@@ -14,18 +14,22 @@ import { ReplyActions, ReplyControls } from './ReplyActions';
|
|||||||
const labels: Record<string,string> = { NeedsAttention: 'Needs attention', DraftReady: 'Draft ready', Completed: 'Completed' };
|
const labels: Record<string,string> = { NeedsAttention: 'Needs attention', DraftReady: 'Draft ready', Completed: 'Completed' };
|
||||||
const initials = (name: string) => name.replace(/<.*>/, '').trim().split(' ').filter(Boolean).slice(0,2).map(x => x[0]).join('').toUpperCase();
|
const initials = (name: string) => name.replace(/<.*>/, '').trim().split(' ').filter(Boolean).slice(0,2).map(x => x[0]).join('').toUpperCase();
|
||||||
const sender = (name: string) => name.replace(/<.*>/, '').replaceAll('"', '').trim();
|
const sender = (name: string) => name.replace(/<.*>/, '').replaceAll('"', '').trim();
|
||||||
const date = (value: string) => new Date(value).toLocaleString(undefined, { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' });
|
const date = (value: string,timeZone: string) => new Date(value).toLocaleString(undefined, { timeZone, day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' });
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [auth,setAuth] = useState<Session|null>(null), [error,setError] = useState(''), [notice,setNotice] = useState('');
|
const [auth,setAuth] = useState<Session|null>(null), [error,setError] = useState(''), [notice,setNotice] = useState('');
|
||||||
const [hotel,setHotel] = useState<Hotel|null>(null), [page,setPage] = useState(location.pathname === '/' ? '/inbox' : location.pathname), [busy,setBusy] = useState(false);
|
const [hotel,setHotel] = useState<Hotel|null>(null), [page,setPage] = useState(location.pathname === '/' ? '/inbox' : location.pathname), [busy,setBusy] = useState(false);
|
||||||
|
const pageRef=useRef(page);
|
||||||
const [conversations,setConversations] = useState<Conversation[]>([]), [knowledge,setKnowledge] = useState<Knowledge[]>([]), [activity,setActivity] = useState<Activity[]>([]), [mailboxes,setMailboxes] = useState<Mailboxes>({ configured:false,items:[] });
|
const [conversations,setConversations] = useState<Conversation[]>([]), [knowledge,setKnowledge] = useState<Knowledge[]>([]), [activity,setActivity] = useState<Activity[]>([]), [mailboxes,setMailboxes] = useState<Mailboxes>({ configured:false,items:[] });
|
||||||
|
const [conversationCursor,setConversationCursor]=useState<string|null>(null);
|
||||||
const [loaded,setLoaded] = useState(false);
|
const [loaded,setLoaded] = useState(false);
|
||||||
async function refresh() {
|
async function refresh() {
|
||||||
const [h,c,k,a,m] = await Promise.all([api<Hotel>('/hotel'),api<Conversation[]>('/conversations'),api<Knowledge[]>('/knowledge'),api<Activity[]>('/activity'),api<Mailboxes>('/mailboxes')]);
|
const [h,c,k,a,m] = await Promise.all([api<Hotel>('/hotel'),api<ConversationPage>('/conversations/page'),api<Knowledge[]>('/knowledge'),api<Activity[]>('/activity'),api<Mailboxes>('/mailboxes')]);
|
||||||
setHotel(h);setConversations(c);setKnowledge(k);setActivity(a);setMailboxes(m);setLoaded(true);
|
setHotel(h);setConversations(c.items);setConversationCursor(c.nextCursor);setKnowledge(k);setActivity(a);setMailboxes(m);setLoaded(true);
|
||||||
}
|
}
|
||||||
useEffect(() => { session().then(setAuth).catch(e=>setError(e.message)); const expired=()=>{setAuth(null);session().then(setAuth).catch(()=>{});setError('Your session has ended. Sign in again.');}; window.addEventListener('session-expired',expired); const pop=()=>setPage(location.pathname);window.addEventListener('popstate',pop);return()=>{window.removeEventListener('session-expired',expired);window.removeEventListener('popstate',pop);}; },[]);
|
async function moreConversations(){if(!conversationCursor)return;const page=await api<ConversationPage>('/conversations/page?cursor='+encodeURIComponent(conversationCursor));setConversations(old=>[...old,...page.items.filter(item=>!old.some(existing=>existing.id===item.id))]);setConversationCursor(page.nextCursor);}
|
||||||
|
useEffect(()=>{pageRef.current=page;},[page]);
|
||||||
|
useEffect(() => { session().then(setAuth).catch(e=>setError(e.message)); const expired=()=>{setAuth(null);session().then(setAuth).catch(()=>{});setError('Your session has ended. Sign in again.');}; window.addEventListener('session-expired',expired); const pop=()=>{if(!window.dispatchEvent(new Event('workspace-navigate',{cancelable:true}))){history.pushState({},'',pageRef.current);return;}setPage(location.pathname==='/'?'/inbox':location.pathname);};window.addEventListener('popstate',pop);return()=>{window.removeEventListener('session-expired',expired);window.removeEventListener('popstate',pop);}; },[]);
|
||||||
useEffect(()=>{if(auth?.user) refresh().catch(e=>setError(e.message));},[auth?.user?.id]);
|
useEffect(()=>{if(auth?.user) refresh().catch(e=>setError(e.message));},[auth?.user?.id]);
|
||||||
useEffect(()=>{if(!notice)return;const timer=setTimeout(()=>setNotice(''),4500);return()=>clearTimeout(timer);},[notice]);
|
useEffect(()=>{if(!notice)return;const timer=setTimeout(()=>setNotice(''),4500);return()=>clearTimeout(timer);},[notice]);
|
||||||
async function run(action:()=>Promise<void>) { if(busy)return; setBusy(true);setError('');try{await action();}catch(e){setError(e instanceof Error?e.message:'Something went wrong.');}finally{setBusy(false);} }
|
async function run(action:()=>Promise<void>) { if(busy)return; setBusy(true);setError('');try{await action();}catch(e){setError(e instanceof Error?e.message:'Something went wrong.');}finally{setBusy(false);} }
|
||||||
@@ -49,7 +53,7 @@ function App() {
|
|||||||
<main className="main">
|
<main className="main">
|
||||||
<header className="topbar"><span><span className="breadcrumb">Workspace</span><ChevronRight size={14}/>{page==='/inbox'?'Inbox':page==='/knowledge'?'Hotel knowledge':page==='/activity'?'Activity':page==='/reservations'?'Reservations':page==='/payments'?'Payments':page==='/automation'?'FAQ automation':page==='/team'?'Your team':page==='/setup'?'Hotel setup':page==='/health'?'Workspace health':'Settings'}</span><div className="topbar-right">{auth.preview&&<span className="preview-pill">Preview · sample data</span>}<span className="draft-mode"><span/>{hotel?.autoReplyMode==='Live'?'FAQ auto-replies enabled':hotel?.staffSendingEnabled?'Staff-approved sending':'Draft-only mode'}</span><button className="icon-button" aria-label="Refresh workspace" disabled={busy} onClick={()=>run(refresh)}><RefreshCw size={17}/></button></div></header>
|
<header className="topbar"><span><span className="breadcrumb">Workspace</span><ChevronRight size={14}/>{page==='/inbox'?'Inbox':page==='/knowledge'?'Hotel knowledge':page==='/activity'?'Activity':page==='/reservations'?'Reservations':page==='/payments'?'Payments':page==='/automation'?'FAQ automation':page==='/team'?'Your team':page==='/setup'?'Hotel setup':page==='/health'?'Workspace health':'Settings'}</span><div className="topbar-right">{auth.preview&&<span className="preview-pill">Preview · sample data</span>}<span className="draft-mode"><span/>{hotel?.autoReplyMode==='Live'?'FAQ auto-replies enabled':hotel?.staffSendingEnabled?'Staff-approved sending':'Draft-only mode'}</span><button className="icon-button" aria-label="Refresh workspace" disabled={busy} onClick={()=>run(refresh)}><RefreshCw size={17}/></button></div></header>
|
||||||
{errorBox}{notice&&<div className="toast" role="status"><Check size={17}/>{notice}</div>}
|
{errorBox}{notice&&<div className="toast" role="status"><Check size={17}/>{notice}</div>}
|
||||||
{!loaded?<div className="loading"><p>Loading your hotel…</p></div>:page==='/health'?<OperationsPage owner={auth.user.role==='Owner'} go={go}/>:page==='/team'?<TeamPage owner={auth.user.role==='Owner'}/>:page==='/setup'?<OnboardingPage owner={auth.user.role==='Owner'} go={go}/>:page==='/inbox'?<InboxPage hotel={hotel!} mailboxes={mailboxes} conversations={conversations} knowledge={knowledge} busy={busy} run={run} onUpdate={c=>setConversations(old=>old.map(x=>x.id===c.id?c:x))} notify={setNotice} go={go}/>:page==='/automation'?<AutomationPage hotel={hotel!} owner={auth.user.role==='Owner'} busy={busy} run={run} onHotel={setHotel}/>:page==='/payments'?<PaymentsPage hotel={hotel!} owner={auth.user.role==='Owner'} busy={busy} run={run} onHotel={setHotel}/>:page==='/reservations'?<PmsPage hotel={hotel!} owner={auth.user.role==='Owner'} busy={busy} run={run} onHotel={setHotel}/>:page==='/knowledge'?<KnowledgePage items={knowledge} canEdit={auth.user.role==='Owner'} busy={busy} run={run} onUpdate={item=>setKnowledge(old=>old.some(x=>x.id===item.id)?old.map(x=>x.id===item.id?item:x):[...old,item])} notify={setNotice}/>:page==='/activity'?<div className="page"><PageHeading eyebrow="A clear record" title="Workspace activity" text="Changes made by your team, in one place."/><div className="activity-list">{activity.length?activity.map(a=><div className="activity-row" key={a.id}><span className="activity-icon"><Check size={18}/></span><div><strong>{a.action}</strong><p>{a.userName}</p></div><time>{date(a.at)}</time></div>):<Empty title="No activity yet" text="Changes to your workspace will appear here."/>}</div></div>:<SettingsPage onMailboxes={setMailboxes} hotel={hotel!} mailboxes={mailboxes} preview={auth.preview} owner={auth.user.role==='Owner'} busy={busy} run={run} onSave={h=>{setHotel(h);setNotice('Hotel settings saved.');}}/>}
|
{!loaded?<div className="loading"><p>Loading your hotel…</p></div>:page==='/health'?<OperationsPage owner={auth.user.role==='Owner'} go={go}/>:page==='/team'?<TeamPage owner={auth.user.role==='Owner'} timeZone={hotel!.timezone}/>:page==='/setup'?<OnboardingPage owner={auth.user.role==='Owner'} go={go}/>:page==='/inbox'?<InboxPage hotel={hotel!} mailboxes={mailboxes} conversations={conversations} hasMore={!!conversationCursor} loadMore={()=>run(moreConversations)} knowledge={knowledge} busy={busy} run={run} onUpdate={c=>setConversations(old=>old.map(x=>x.id===c.id?c:x))} notify={setNotice} go={go}/>:page==='/automation'?<AutomationPage hotel={hotel!} owner={auth.user.role==='Owner'} busy={busy} run={run} onHotel={setHotel}/>:page==='/payments'?<PaymentsPage hotel={hotel!} owner={auth.user.role==='Owner'} busy={busy} run={run} onHotel={setHotel}/>:page==='/reservations'?<PmsPage hotel={hotel!} owner={auth.user.role==='Owner'} busy={busy} run={run} onHotel={setHotel}/>:page==='/knowledge'?<KnowledgePage items={knowledge} canEdit={auth.user.role==='Owner'} busy={busy} run={run} onUpdate={item=>setKnowledge(old=>old.some(x=>x.id===item.id)?old.map(x=>x.id===item.id?item:x):[...old,item])} notify={setNotice}/>:page==='/activity'?<div className="page"><PageHeading eyebrow="A clear record" title="Workspace activity" text="Changes made by your team, in one place."/><div className="activity-list">{activity.length?activity.map(a=><div className="activity-row" key={a.id}><span className="activity-icon"><Check size={18}/></span><div><strong>{a.action}</strong><p>{a.userName}</p></div><time>{date(a.at,hotel!.timezone)}</time></div>):<Empty title="No activity yet" text="Changes to your workspace will appear here."/>}</div></div>:<SettingsPage onMailboxes={setMailboxes} hotel={hotel!} mailboxes={mailboxes} preview={auth.preview} owner={auth.user.role==='Owner'} busy={busy} run={run} onSave={h=>{setHotel(h);setNotice('Hotel settings saved.');}}/>}
|
||||||
</main>
|
</main>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
@@ -60,7 +64,7 @@ function Login({preview,onLogin,onPreview,busy,error}:{preview:boolean;onLogin:(
|
|||||||
return <div className="login-layout"><section className="login-story"><div className="brand"><span className="brand-mark">g</span>guestops.</div><div><span className="eyebrow">A little more time for your guests</span><h1>Great hospitality.<br/>A calmer inbox.</h1><p>Your conversations, hotel knowledge and team.<br/>Together in one thoughtful workspace.</p><div className="login-detail"><Inbox size={24}/><span>Less time sorting emails.<br/><strong>More time making guests feel welcome.</strong></span></div></div><small>Built around the way hotels work.</small></section><section className="login-form"><div><span className="eyebrow">Your hotel workspace</span><h1>Welcome back</h1><p>Sign in to take care of your guests.</p>{error}<form onSubmit={e=>{e.preventDefault();onLogin(email,password);}}><label>Email address<input type="email" autoComplete="username" value={email} onChange={e=>setEmail(e.target.value)} placeholder="you@yourhotel.com" required/></label><label>Password<input type="password" autoComplete="current-password" value={password} onChange={e=>setPassword(e.target.value)} required/></label><button className="button primary wide" disabled={busy}>{busy?'Signing in…':'Sign in'}<ArrowUpRight size={18}/></button></form><p className="small muted">Need access or help signing in? Contact your hotel administrator.</p>{preview&&<div className="preview-login"><span>Explore the interface with sample conversations.</span><button className="button secondary wide" onClick={onPreview} disabled={busy}>Open preview workspace<ArrowUpRight size={17}/></button><small>Preview changes are temporary. No real emails are sent.</small></div>}</div></section></div>;
|
return <div className="login-layout"><section className="login-story"><div className="brand"><span className="brand-mark">g</span>guestops.</div><div><span className="eyebrow">A little more time for your guests</span><h1>Great hospitality.<br/>A calmer inbox.</h1><p>Your conversations, hotel knowledge and team.<br/>Together in one thoughtful workspace.</p><div className="login-detail"><Inbox size={24}/><span>Less time sorting emails.<br/><strong>More time making guests feel welcome.</strong></span></div></div><small>Built around the way hotels work.</small></section><section className="login-form"><div><span className="eyebrow">Your hotel workspace</span><h1>Welcome back</h1><p>Sign in to take care of your guests.</p>{error}<form onSubmit={e=>{e.preventDefault();onLogin(email,password);}}><label>Email address<input type="email" autoComplete="username" value={email} onChange={e=>setEmail(e.target.value)} placeholder="you@yourhotel.com" required/></label><label>Password<input type="password" autoComplete="current-password" value={password} onChange={e=>setPassword(e.target.value)} required/></label><button className="button primary wide" disabled={busy}>{busy?'Signing in…':'Sign in'}<ArrowUpRight size={18}/></button></form><p className="small muted">Need access or help signing in? Contact your hotel administrator.</p>{preview&&<div className="preview-login"><span>Explore the interface with sample conversations.</span><button className="button secondary wide" onClick={onPreview} disabled={busy}>Open preview workspace<ArrowUpRight size={17}/></button><small>Preview changes are temporary. No real emails are sent.</small></div>}</div></section></div>;
|
||||||
}
|
}
|
||||||
type Run=(a:()=>Promise<void>)=>Promise<void>;
|
type Run=(a:()=>Promise<void>)=>Promise<void>;
|
||||||
function InboxPage({hotel,mailboxes,conversations,knowledge,busy,run,onUpdate,notify,go}:{hotel:Hotel;mailboxes:Mailboxes;conversations:Conversation[];knowledge:Knowledge[];busy:boolean;run:Run;onUpdate:(c:Conversation)=>void;notify:(s:string)=>void;go:(s:string)=>void}){
|
function InboxPage({hotel,mailboxes,conversations,hasMore,loadMore,knowledge,busy,run,onUpdate,notify,go}:{hotel:Hotel;mailboxes:Mailboxes;conversations:Conversation[];hasMore:boolean;loadMore:()=>void;knowledge:Knowledge[];busy:boolean;run:Run;onUpdate:(c:Conversation)=>void;notify:(s:string)=>void;go:(s:string)=>void}){
|
||||||
const [filter,setFilter]=useState('All'),[search,setSearch]=useState(''),[selected,setSelected]=useState<string|null>(null),[draft,setDraft]=useState(''),[mobileDetail,setMobileDetail]=useState(false);
|
const [filter,setFilter]=useState('All'),[search,setSearch]=useState(''),[selected,setSelected]=useState<string|null>(null),[draft,setDraft]=useState(''),[mobileDetail,setMobileDetail]=useState(false);
|
||||||
const filtered=conversations.filter(c=>(filter==='All'||c.status===filter)&&(c.subject+' '+c.from+' '+c.body).toLowerCase().includes(search.toLowerCase()));
|
const filtered=conversations.filter(c=>(filter==='All'||c.status===filter)&&(c.subject+' '+c.from+' '+c.body).toLowerCase().includes(search.toLowerCase()));
|
||||||
const current=filtered.find(c=>c.id===selected)||filtered[0];
|
const current=filtered.find(c=>c.id===selected)||filtered[0];
|
||||||
@@ -71,9 +75,9 @@ function InboxPage({hotel,mailboxes,conversations,knowledge,busy,run,onUpdate,no
|
|||||||
async function save() {if(!current)return;await run(async()=>{onUpdate(await api<Conversation>(`/conversations/${current.id}/draft`,'PUT',{draft,version:current.version}));notify('Draft saved. Nothing has been sent.');});}
|
async function save() {if(!current)return;await run(async()=>{onUpdate(await api<Conversation>(`/conversations/${current.id}/draft`,'PUT',{draft,version:current.version}));notify('Draft saved. Nothing has been sent.');});}
|
||||||
async function resolve() {if(!current)return;await run(async()=>{onUpdate(await api<Conversation>(`/conversations/${current.id}/status`,'PUT',{status:current.status==='Completed'?'NeedsAttention':'Completed',version:current.version}));notify(current.status==='Completed'?'Conversation reopened.':'Conversation marked completed.');});}
|
async function resolve() {if(!current)return;await run(async()=>{onUpdate(await api<Conversation>(`/conversations/${current.id}/status`,'PUT',{status:current.status==='Completed'?'NeedsAttention':'Completed',version:current.version}));notify(current.status==='Completed'?'Conversation reopened.':'Conversation marked completed.');});}
|
||||||
return <div className="inbox-page"><div className="inbox-heading"><PageHeading eyebrow="A warm welcome starts here" title="Your guest inbox" text={needs?`${needs} conversations need your attention. Let's make their day.`:'A little space to focus on your guests.'}/><div className="mini-stats"><div><strong>{needs}</strong><span>Need attention</span></div><div><strong>{ready}</strong><span>Drafts ready</span></div></div></div>
|
return <div className="inbox-page"><div className="inbox-heading"><PageHeading eyebrow="A warm welcome starts here" title="Your guest inbox" text={needs?`${needs} conversations need your attention. Let's make their day.`:'A little space to focus on your guests.'}/><div className="mini-stats"><div><strong>{needs}</strong><span>Need attention</span></div><div><strong>{ready}</strong><span>Drafts ready</span></div></div></div>
|
||||||
<div className="inbox-toolbar"><div className="tabs" role="group" aria-label="Filter conversations">{[['All','All messages'],['NeedsAttention','Needs attention'],['DraftReady','Drafts'],['Completed','Completed']].map(([key,label])=><button key={key} className={filter===key?'tab selected':'tab'} onClick={()=>{if(current&&draft!==current.draft&&!window.confirm('Discard your unsaved draft changes?'))return;setFilter(key);}}>{label}{key==='NeedsAttention'&&needs>0&&<span>{needs}</span>}</button>)}</div><label className="search"><Search size={17}/><input aria-label="Search conversations" placeholder="Search messages…" value={search} onChange={e=>setSearch(e.target.value)}/></label></div>
|
<div className="inbox-toolbar"><div className="tabs" role="group" aria-label="Filter conversations">{[['All','All messages'],['NeedsAttention','Needs attention'],['DraftReady','Drafts'],['Completed','Completed']].map(([key,label])=><button key={key} className={filter===key?'tab selected':'tab'} onClick={()=>{if(current&&draft!==current.draft&&!window.confirm('Discard your unsaved draft changes?'))return;setFilter(key);}}>{label}{key==='NeedsAttention'&&needs>0&&<span>{needs}</span>}</button>)}</div><label className="search"><Search size={17}/><input aria-label="Search conversations" placeholder="Search loaded messages…" value={search} onChange={e=>{if(current&&draft!==current.draft&&!window.confirm('Discard your unsaved draft changes?'))return;setSearch(e.target.value);}}/></label></div>
|
||||||
{!conversations.length?<div className="onboard-empty"><Empty title="A calmer inbox starts here" text="Connect your hotel's Google mailbox to bring recent guest conversations into GuestOps."/><button className="button primary" onClick={()=>go('/settings')}>Connect your mailbox<ArrowUpRight size={17}/></button></div>:<div className={'inbox-panels '+(mobileDetail?'show-detail':'')}><section className="message-list" aria-label="Conversations"><div className="list-title">{filtered.length} conversation{filtered.length===1?'':'s'}<span>Newest first<ChevronDown size={13}/></span></div>{filtered.map((c,i)=><button key={c.id} className={'message-card '+(current?.id===c.id?'current':'')} onClick={()=>select(c)}><div className="message-top"><span className={'avatar tone-'+i%4}>{initials(sender(c.from))}</span><strong>{sender(c.from)}</strong><time>{new Date(c.receivedAt).toLocaleTimeString([],{hour:'2-digit',minute:'2-digit'})}</time></div><h3>{c.subject}</h3><p>{c.body}</p><div className="message-bottom"><span className={'status '+c.status}>{c.status==='DraftReady'?<FileText size={12}/>:c.status==='Completed'?<CheckCheck size={12}/>:<Clock3 size={12}/>} {labels[c.status]}</span><span>{c.category}</span></div></button>)}{!filtered.length&&<Empty title="Nothing here just now" text="Try another filter or search."/>}</section>
|
{!conversations.length?<div className="onboard-empty"><Empty title="A calmer inbox starts here" text="Connect your hotel's Google mailbox to bring recent guest conversations into GuestOps."/><button className="button primary" onClick={()=>go('/settings')}>Connect your mailbox<ArrowUpRight size={17}/></button></div>:<div className={'inbox-panels '+(mobileDetail?'show-detail':'')}><section className="message-list" aria-label="Conversations"><div className="list-title">{filtered.length} loaded conversation{filtered.length===1?'':'s'}<span>Newest first<ChevronDown size={13}/></span></div>{filtered.map((c,i)=><button key={c.id} className={'message-card '+(current?.id===c.id?'current':'')} onClick={()=>select(c)}><div className="message-top"><span className={'avatar tone-'+i%4}>{initials(sender(c.from))}</span><strong>{sender(c.from)}</strong><time>{new Date(c.receivedAt).toLocaleTimeString([],{timeZone:hotel.timezone,hour:'2-digit',minute:'2-digit'})}</time></div><h3>{c.subject}</h3><p>{c.body}</p><div className="message-bottom"><span className={'status '+c.status}>{c.status==='DraftReady'?<FileText size={12}/>:c.status==='Completed'?<CheckCheck size={12}/>:<Clock3 size={12}/>} {labels[c.status]}</span><span>{c.category}</span></div></button>)}{hasMore&&<button className="button secondary wide" disabled={busy} onClick={loadMore}>Load 50 older conversations</button>}{!filtered.length&&<Empty title="Nothing here just now" text="Try another filter or search."/>}</section>
|
||||||
<section className="conversation" aria-label="Selected conversation">{current?<><div className="conversation-tools"><button className="button text mobile-back" onClick={()=>setMobileDetail(false)}><ArrowLeft size={16}/>Back</button><span className="category-label">{current.category}</span><button className="button secondary compact" onClick={resolve} disabled={busy||!!current.delivery&¤t.delivery.state!=='Sent'}><Check size={16}/>{current.status==='Completed'?'Reopen':'Mark complete'}</button></div><div className="conversation-body"><h2>{current.subject}</h2><div className="sender-line"><span className="avatar tone-0">{initials(sender(current.from))}</span><div><strong>{sender(current.from)}</strong><small>To your hotel · {date(current.receivedAt)}</small></div></div><div className="email-body">{current.body}</div>{current.note&&<div className="staff-note"><CircleHelp size={17}/>{current.note}</div>}<div className="reply-box"><div className="reply-header"><span><FileText size={17}/><strong>Your reply draft</strong></span><span className="small muted">Only visible to your team</span></div><label className="sr-only" htmlFor="draft">Reply draft</label><textarea id="draft" disabled={!!current.delivery||busy} value={draft} onChange={e=>setDraft(e.target.value)} placeholder="Write a thoughtful reply…"/><div className="knowledge-insert"><BookOpen size={15}/><select disabled={!!current.delivery||busy} aria-label="Insert an approved hotel answer" value="" onChange={e=>{const k=knowledge.find(x=>x.id===e.target.value);if(k)setDraft(d=>d+(d?'\n\n':'')+k.answer);}}><option value="">Insert an approved hotel answer</option>{knowledge.filter(k=>k.approved).map(k=><option key={k.id} value={k.id}>{k.title}</option>)}</select></div><div className="reply-footer"><span><ShieldCheck size={15}/>No automatic sending</span><button className="button primary" disabled={busy||!!current.delivery||draft===current.draft} onClick={save}><Save size={16}/>Save draft</button></div></div><ReplyActions message={current} hotel={hotel} mailboxes={mailboxes} knowledge={knowledge} dirty={draft!==current.draft} busy={busy} run={run} onUpdate={onUpdate}/><div className="below-draft"><span>Check the reply and recipient before sending.</span>{current.providerThreadId&&/^[a-zA-Z0-9]+$/.test(current.providerThreadId)&&<a href={'https://mail.google.com/mail/u/0/#inbox/'+encodeURIComponent(current.providerThreadId)} target="_blank" rel="noopener noreferrer">Open in Gmail<ArrowUpRight size={14}/></a>}</div></div></>:<Empty title="Choose a conversation" text="Read a message and prepare a reply here."/>}</section></div>}</div>;
|
<section className="conversation" aria-label="Selected conversation">{current?<><div className="conversation-tools"><button className="button text mobile-back" onClick={()=>setMobileDetail(false)}><ArrowLeft size={16}/>Back</button><span className="category-label">{current.category}</span><button className="button secondary compact" onClick={resolve} disabled={busy||!!current.delivery&¤t.delivery.state!=='Sent'}><Check size={16}/>{current.status==='Completed'?'Reopen':'Mark complete'}</button></div><div className="conversation-body"><h2>{current.subject}</h2><div className="sender-line"><span className="avatar tone-0">{initials(sender(current.from))}</span><div><strong>{sender(current.from)}</strong><small>To your hotel · {date(current.receivedAt,hotel.timezone)}</small></div></div><div className="email-body">{current.body}</div>{current.note&&<div className="staff-note"><CircleHelp size={17}/>{current.note}</div>}<div className="reply-box"><div className="reply-header"><span><FileText size={17}/><strong>Your reply draft</strong></span><span className="small muted">Only visible to your team</span></div><label className="sr-only" htmlFor="draft">Reply draft</label><textarea id="draft" disabled={!!current.delivery||busy} value={draft} onChange={e=>setDraft(e.target.value)} placeholder="Write a thoughtful reply…"/><div className="knowledge-insert"><BookOpen size={15}/><select disabled={!!current.delivery||busy} aria-label="Insert an approved hotel answer" value="" onChange={e=>{const k=knowledge.find(x=>x.id===e.target.value);if(k)setDraft(d=>d+(d?'\n\n':'')+k.answer);}}><option value="">Insert an approved hotel answer</option>{knowledge.filter(k=>k.approved).map(k=><option key={k.id} value={k.id}>{k.title}</option>)}</select></div><div className="reply-footer"><span><ShieldCheck size={15}/>No automatic sending</span><button className="button primary" disabled={busy||!!current.delivery||draft===current.draft} onClick={save}><Save size={16}/>Save draft</button></div></div><ReplyActions message={current} hotel={hotel} mailboxes={mailboxes} knowledge={knowledge} dirty={draft!==current.draft} busy={busy} run={run} onUpdate={onUpdate}/><div className="below-draft"><span>Check the reply and recipient before sending.</span>{current.providerThreadId&&/^[a-zA-Z0-9]+$/.test(current.providerThreadId)&&<a href={'https://mail.google.com/mail/u/0/#inbox/'+encodeURIComponent(current.providerThreadId)} target="_blank" rel="noopener noreferrer">Open in Gmail<ArrowUpRight size={14}/></a>}</div></div></>:<Empty title="Choose a conversation" text="Read a message and prepare a reply here."/>}</section></div>}</div>;
|
||||||
}
|
}
|
||||||
function KnowledgePage({items,canEdit,busy,run,onUpdate,notify}:{items:Knowledge[];canEdit:boolean;busy:boolean;run:Run;onUpdate:(k:Knowledge)=>void;notify:(s:string)=>void}){
|
function KnowledgePage({items,canEdit,busy,run,onUpdate,notify}:{items:Knowledge[];canEdit:boolean;busy:boolean;run:Run;onUpdate:(k:Knowledge)=>void;notify:(s:string)=>void}){
|
||||||
const [edit,setEdit]=useState<Knowledge|null>(null),[search,setSearch]=useState('');
|
const [edit,setEdit]=useState<Knowledge|null>(null),[search,setSearch]=useState('');
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export function hotelTime(value:string,timeZone:string,options?:Intl.DateTimeFormatOptions){
|
||||||
|
return new Intl.DateTimeFormat(undefined,{timeZone,...options}).format(new Date(value));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user