Compare commits

...
Author SHA1 Message Date
fred 1e069946ff contract(onboarding-wizard): revision 15 — bootstrap-status envelope split (NEW-20 residual), active-window mutant attribution (NEW-22)
ci/woodpecker/pr/ci Pipeline was successful
Sol r14 re-review left two findings. NEW-20 residual (BLOCKER): §2.3
closed the bootstrap-status response to epoch/mode with no other field,
conflicting with contract 5 §4.3's mandatory correlation echo on mapped
operations (§§1.1, 7 item 8). Rev 14's state-derived/envelope split is
now applied to bootstrap-status: §2.3 bounds state-derived content only
and carries the contract 5 §4 envelope; §6 item 2's closed-field
assertion and §7 item 2's description follow. Contract 5 not amended.

NEW-22 (MAJOR): the active-window witness claimed its seed-workspace-
scoped mutant fails branches (b) and (c); it passes (c). The witness now
attributes (b) to that mutant, names the separate all-workspace mutant
branch (c) catches, and states branches (a)/(b)/(c) start from isolated
copies of the same incomplete pre-state.

Preamble: Revision 15 paragraph; Revision 14 superseding note.
2026-08-27 05:19:30 -05:00
fred f97d7220e3 contract(onboarding-wizard): revision 14 — query/originate loop, RBAC §1 exception ratified, contract 5 envelope reconciled, one refusal order
ci/woodpecker/pr/ci Pipeline was successful
Addresses sol re-review 13 (NEW-18/NEW-19 residuals, NEW-20, NEW-21):

- NEW-18: seed-progress query response is a closed discriminated union
  (next index | typed complete variant); normative query/originate loop
  — stop on complete, re-query on canonical refusal, continue only on a
  strictly-later result, surface a fault on an unchanged index. New
  witnesses: same-designation race (with unchanged-index fault variant)
  and completed-world stop run of the actual fresh client; cross-surface
  refusal-shape control added to the two-world query witness.
- NEW-19: RBAC §1 expressly named among amended surfaces — narrow
  ratified exception making the designation a fourth authority source
  inside the mechanical origination scope only (§1.2, §4.3, §7 item
  12). New active-window boundary witness: canonical tuple succeeds
  while non-canonical and non-seed-workspace commands refuse in the
  SAME incomplete state; predecessor- and successor-created content
  reads refused post-origination.
- NEW-20: state-derived disclosure split from mandatory envelope
  metadata everywhere — origination and query responses remain ordinary
  contract 5 §4 result DTOs carrying the correlation envelope; contract
  5 not amended. §6.1 closed-schema assertion covers both halves.
- NEW-21: result-disclosure paragraph restates the operative order —
  fresh-mutation authorization first (owning family's refusal), then
  seed-boundary gate before fence presence and canonical-reference
  resolution, constant shape scoped to callers that reached the gate;
  child-race control asserts the refusal class, pinning the order.
2026-08-27 04:44:57 -05:00
fred 552650a69b contract(onboarding-wizard): revision 13 — seed-progress query, generalized designation-derived authority
ci/woodpecker/pr/ci Pipeline was successful
Addresses sol r12 verdict (NEW-18, NEW-19):

- NEW-18: new mapped, designation-only seed-progress query returning
  exactly the next unrecorded canonical position index (or completion
  marker); screening evaluated before any fence state, non-designated
  submitters refused byte-shape-identically across recorded and
  unrecorded worlds; closed read set (position-committed existence
  flags + designation, §6.1); origin fresh-client resume and successor
  completion both query first and originate from the returned index.
- NEW-19: designation-derived authority generalized to the
  actor-authorization component of every canonical position's owning
  family, each surface named expressly (contract 2 §4; RBAC §§2-3
  workspace-content authorization; native-kanban SOT REQ-TEN-001 /
  A1 §8.1.3) as coupled severable-together amendments under one
  mechanically decidable scope, with a defined result-disclosure
  boundary (canonical outcome fields only).
- §6.7: seed-progress two-world refusal, entitlement witness with the
  actual fresh client run against both worlds, content-position
  completion in both recovery variants, non-canonical content
  refusal, result-disclosure witness.
- §7 item 12 now three coupled amendments; §1.1/§1.2/§5.3-5.4/§6.1
  disclosures updated; preamble Revision 13 paragraph.
2026-08-27 04:12:05 -05:00
fred 10e82d05c0 contract 7 rev 12: pure designation transfer, epoch-derived account-free seed tuples, designation-derived origination authority
ci/woodpecker/pr/ci Pipeline was successful
Answers sol re-review 10 (NEW-12/NEW-13/NEW-14 residuals, NEW-16, NEW-17):

- Canonical seed tuples fully epoch-derived and account-free: no
  generated id or account identifier in any canonical payload or
  scope; child positions reference parents by epoch-scoped canonical
  seed role, resolved server-side at execution (canonical-reference
  resolution); position 1 carries no initial-owner field — the
  contract 2 §4.3 default binds owner to the acting designation as a
  recorded outcome. Byte-stability absolute; post-succession replay
  compares equal by construction (NEW-13).
- Succession reduced to a pure designation transfer: condition (a) =
  identity §7.1 unavailability alone (unable disjunct removed), no
  grant conferred, reads identity/platform/epoch state only, closed
  write set = designation update + one audit event. World-independent
  unconditionally, self-revocation pair included (NEW-12); post-
  completion succession confers nothing (NEW-16).
- Designation-derived origination authority: scoped contract 2 §4
  amendment (§7 item 12) — the current designation satisfies the
  hierarchy-authority component for fresh origination of unoriginated
  canonical positions only; no read/replay/standing authority.
- §6.1 succession-write inventory closed in both directions; no-seed-
  input static assertion (NEW-17).
- Revision-10 preamble vocabulary corrected to the banned state
  identity defines (NEW-14).
- §6.7 reworked: strengthened two-world control (event content, grant-
  table delta, full-command timing), new self-revocation two-world
  refusal, designation-derived completion, post-completion
  harmlessness, post-succession replay digest-equality, empty-prefix
  digest-equality witnesses; out-of-order origination witness.
2026-08-27 03:38:06 -05:00
fred 83142e1b79 docs: onboarding-wizard contract revision 11 (sol r10 NEW-12/13/14/15: world-independent succession with conferred position-1 authority, unavailable-or-unable re-succession, §7.1 predicate collapse with forward constraint, dual identity-surface disclosure)
ci/woodpecker/pr/ci Pipeline was successful
2026-08-27 02:50:32 -05:00
fred 3824fc6a37 docs: onboarding-wizard contract revision 10 (sol r9 NEW-11: seed-origin becomes a designation with a disclosed succession command — origin loss recoverable without factory reset, no-oracle shape preserved)
ci/woodpecker/pr/ci Pipeline failed
2026-08-26 23:21:33 -05:00
fred 535ac2d860 docs: onboarding-wizard contract revision 9 (sol r8 NEW-9 residual: prefix-derived seed tuples + seed-origin gate; NEW-10: target-result authorization on every replay mode)
ci/woodpecker/pr/ci Pipeline failed
2026-08-26 22:56:59 -05:00
fred eff3b91478 docs: onboarding-wizard contract revision 8 (sol r7 NEW-9: shared replay target-result authorization, seed-only boundary, replay access event)
ci/woodpecker/pr/ci Pipeline was canceled
2026-08-26 22:30:22 -05:00
fred 84fe8b6ef1 docs: onboarding-wizard contract revision 7 (sol r6 F6 residual + NEW-8)
ci/woodpecker/pr/ci Pipeline was successful
2026-08-26 21:43:57 -05:00
fred b8b257e1ec docs: onboarding-wizard contract revision 6 (sol r5 residual F7 + N7 seed immutability)
ci/woodpecker/pr/ci Pipeline was successful
2026-08-26 21:08:33 -05:00
fred 0162443a38 docs: onboarding-wizard contract revision 5 (sol re-review 3 residuals + N5/N6)
ci/woodpecker/pr/ci Pipeline was successful
2026-08-26 20:40:14 -05:00
fred e58d0a5447 docs: onboarding-wizard contract revision 4 (sol re-review 2 residuals + N3/N4)
ci/woodpecker/pr/ci Pipeline was canceled
- F2: bootstrap-status closed two-field schema (epoch enum + pre-epoch-only
  mode), post-epoch mode-field absence witnessed, contract 6 \u00a72.2 amendment
  disclosed (\u00a77.9)
- F5/N4: contract 5 \u00a73.1 rank-6 mapping expansion disclosed naming the rows
  to amend (\u00a77.8); \u00a71.1 states which families are live vs amended
- F7: complete idempotency envelope \u2014 fence records operation/actor/scope/
  payload digest, re-authorized replay, collision refusal, no error replay,
  concurrent loser receives winner's recorded outcome; witnesses added
- N1/N3: post-epoch application phase replaced by a single bootstrap finalize
  command (one transaction: admin + epoch close + carried settings/registration/
  JIT/seed-parameter writes under the new admin); password-only v1 first admin
  (\u00a77.10); seed sequence derived from canonical state; \u00a76.11 uses the
  authentication-failure class
2026-08-26 20:21:55 -05:00
fred eb48d72f67 docs(wizard): revision 3 — client-side composition, collect-first settings, idempotency fence, bound name sources (sol r2 residuals + N1/N2)
ci/woodpecker/pr/ci Pipeline was canceled
2026-08-26 19:55:45 -05:00
fred 666e3dbf20 docs: onboarding wizard revision 2 — first-company authority, mode as input, choice/witness repairs (sol F1-F9)
ci/woodpecker/pr/ci Pipeline is running
2026-08-26 19:13:36 -05:00
fred 1c9a3ddefb docs: onboarding wizard contract (S2 contract 3)
ci/woodpecker/pr/ci Pipeline was canceled
2026-08-26 18:46:14 -05:00
fred 49b7943420 fix(gateway): scope /api/teams endpoints to team membership (#1428) (#1429)
ci/woodpecker/push/publish Pipeline is pending
2026-08-26 22:45:54 +00:00
fred 19e16bd44f ci: publish web+appservice sha images on next (#1407) (#1427)
ci/woodpecker/push/publish Pipeline was canceled
2026-08-26 22:42:03 +00:00
5 changed files with 2159 additions and 22 deletions
+27 -14
View File
@@ -32,6 +32,11 @@ variables:
# non-excluded change still builds, so no transitive dep can silently go stale.
# (Woodpecker: `when` entries are OR'd; `path` applies to push/PR only — hence
# the separate `event: tag` entry.)
# #1407: ONE shared anchor for all three image steps. A second main-only
# anchor previously gated build-web/build-appservice, so next-lane pushes
# published gateway sha images with no web/appservice counterpart — no
# sha-parity set existed for next-lane containerized deploys. Every image
# step now builds on next too (sha-only destinations, enforced per step).
- &image_build_when
- event: tag
- event: [push, manual]
@@ -44,16 +49,6 @@ variables:
- '.woodpecker/**'
- event: [push, manual]
branch: next
- &main_image_build_when
- event: tag
- event: [push, manual]
branch: main
path:
exclude:
- 'packages/mosaic/**'
- 'docs/**'
- '**/*.md'
- '.woodpecker/**'
when:
- branch: [main, next]
@@ -474,7 +469,7 @@ steps:
build-appservice:
image: gcr.io/kaniko-project/executor:debug
when: *main_image_build_when
when: *image_build_when
environment:
REGISTRY_USER:
from_secret: REGISTRY_USERNAME
@@ -488,8 +483,17 @@ steps:
- echo "{\"auths\":{\"git.mosaicstack.dev\":{\"username\":\"$REGISTRY_USER\",\"password\":\"$REGISTRY_PASS\"}}}" > /kaniko/.docker/config.json
- |
DESTINATIONS="--destination git.mosaicstack.dev/mosaicstack/stack/appservice:sha-${CI_COMMIT_SHA:0:7}"
if [ "$CI_COMMIT_BRANCH" = "main" ]; then
if [ "$CI_COMMIT_BRANCH" = "next" ]; then
if [ -n "$CI_COMMIT_TAG" ]; then
echo "[publish] FATAL: next appservice publish must be sha-only; refusing tag '$CI_COMMIT_TAG'" >&2
exit 1
fi
echo "[publish] next appservice publish is sha-only"
elif [ "$CI_COMMIT_BRANCH" = "main" ]; then
DESTINATIONS="$DESTINATIONS --destination git.mosaicstack.dev/mosaicstack/stack/appservice:latest"
elif [ -z "$CI_COMMIT_TAG" ]; then
echo "[publish] FATAL: appservice image publish may only run for main, next, or tag events" >&2
exit 1
fi
if [ -n "$CI_COMMIT_TAG" ]; then
DESTINATIONS="$DESTINATIONS --destination git.mosaicstack.dev/mosaicstack/stack/appservice:$CI_COMMIT_TAG"
@@ -509,7 +513,7 @@ steps:
build-web:
image: gcr.io/kaniko-project/executor:debug
when: *main_image_build_when
when: *image_build_when
environment:
REGISTRY_USER:
from_secret: REGISTRY_USERNAME
@@ -523,8 +527,17 @@ steps:
- echo "{\"auths\":{\"git.mosaicstack.dev\":{\"username\":\"$REGISTRY_USER\",\"password\":\"$REGISTRY_PASS\"}}}" > /kaniko/.docker/config.json
- |
DESTINATIONS="--destination git.mosaicstack.dev/mosaicstack/stack/web:sha-${CI_COMMIT_SHA:0:7}"
if [ "$CI_COMMIT_BRANCH" = "main" ]; then
if [ "$CI_COMMIT_BRANCH" = "next" ]; then
if [ -n "$CI_COMMIT_TAG" ]; then
echo "[publish] FATAL: next web publish must be sha-only; refusing tag '$CI_COMMIT_TAG'" >&2
exit 1
fi
echo "[publish] next web publish is sha-only"
elif [ "$CI_COMMIT_BRANCH" = "main" ]; then
DESTINATIONS="$DESTINATIONS --destination git.mosaicstack.dev/mosaicstack/stack/web:latest"
elif [ -z "$CI_COMMIT_TAG" ]; then
echo "[publish] FATAL: web image publish may only run for main, next, or tag events" >&2
exit 1
fi
if [ -n "$CI_COMMIT_TAG" ]; then
DESTINATIONS="$DESTINATIONS --destination git.mosaicstack.dev/mosaicstack/stack/web:$CI_COMMIT_TAG"
@@ -0,0 +1,123 @@
import 'reflect-metadata';
import { type CanActivate, type ExecutionContext, type INestApplication } from '@nestjs/common';
import { FastifyAdapter, type NestFastifyApplication } from '@nestjs/platform-fastify';
import { Test } from '@nestjs/testing';
import request from 'supertest';
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import { AuthGuard } from '../auth/auth.guard.js';
import { TeamsController } from './teams.controller.js';
import { TeamsService } from './teams.service.js';
const teamAlpha = { id: 'team-alpha', name: 'Alpha' };
const teamBeta = { id: 'team-beta', name: 'Beta' };
// user-1 is a member of team-alpha only; admin-1 has role admin.
let currentUser: { id: string; role?: string } = { id: 'user-1' };
const teamsServiceMock = {
findAll: vi.fn(() => Promise.resolve([teamAlpha, teamBeta])),
findAllForUser: vi.fn((userId: string) =>
Promise.resolve(userId === 'user-1' ? [teamAlpha] : []),
),
findById: vi.fn((id: string) => Promise.resolve([teamAlpha, teamBeta].find((t) => t.id === id))),
listMembers: vi.fn(() => Promise.resolve([{ teamId: 'team-alpha', userId: 'user-1' }])),
isMember: vi.fn((teamId: string, userId: string) =>
Promise.resolve(teamId === 'team-alpha' && userId === 'user-1'),
),
};
const authGuard: CanActivate = {
canActivate(context: ExecutionContext): boolean {
const requestContext = context
.switchToHttp()
.getRequest<{ user?: { id: string; role?: string } }>();
requestContext.user = currentUser;
return true;
},
};
describe('teams endpoints are scoped to membership', () => {
let app: INestApplication;
beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
controllers: [TeamsController],
providers: [{ provide: TeamsService, useValue: teamsServiceMock }],
})
.overrideGuard(AuthGuard)
.useValue(authGuard)
.compile();
app = moduleRef.createNestApplication<NestFastifyApplication>(new FastifyAdapter());
await app.init();
await app.getHttpAdapter().getInstance().ready();
});
beforeEach(() => {
currentUser = { id: 'user-1' };
vi.clearAllMocks();
});
afterAll(async () => {
await app.close();
});
it('GET /api/teams returns only the teams the user belongs to', async () => {
const response = await request(app.getHttpServer()).get('/api/teams');
expect(response.status).toBe(200);
expect(response.body).toEqual([teamAlpha]);
expect(teamsServiceMock.findAll).not.toHaveBeenCalled();
});
it('GET /api/teams returns every team for an admin', async () => {
currentUser = { id: 'admin-1', role: 'admin' };
const response = await request(app.getHttpServer()).get('/api/teams');
expect(response.status).toBe(200);
expect(response.body).toEqual([teamAlpha, teamBeta]);
expect(teamsServiceMock.findAllForUser).not.toHaveBeenCalled();
});
it('GET /api/teams/:teamId returns 403 for a non-member', async () => {
const response = await request(app.getHttpServer()).get('/api/teams/team-beta');
expect(response.status).toBe(403);
});
it('GET /api/teams/:teamId returns 404 for a missing team', async () => {
const response = await request(app.getHttpServer()).get('/api/teams/team-missing');
expect(response.status).toBe(404);
});
it('GET /api/teams/:teamId returns the team for a member', async () => {
const response = await request(app.getHttpServer()).get('/api/teams/team-alpha');
expect(response.status).toBe(200);
expect(response.body).toEqual(teamAlpha);
});
it('GET /api/teams/:teamId/members returns 403 for a non-member and members for a member', async () => {
const denied = await request(app.getHttpServer()).get('/api/teams/team-beta/members');
expect(denied.status).toBe(403);
expect(teamsServiceMock.listMembers).not.toHaveBeenCalled();
const allowed = await request(app.getHttpServer()).get('/api/teams/team-alpha/members');
expect(allowed.status).toBe(200);
expect(allowed.body).toEqual([{ teamId: 'team-alpha', userId: 'user-1' }]);
});
it('GET /api/teams/:teamId/members/:userId allows a self-lookup on any team', async () => {
const response = await request(app.getHttpServer()).get('/api/teams/team-beta/members/user-1');
expect(response.status).toBe(200);
expect(response.body).toEqual({ isMember: false });
});
it('GET /api/teams/:teamId/members/:userId denies looking up another user on a foreign team', async () => {
const response = await request(app.getHttpServer()).get('/api/teams/team-beta/members/user-2');
expect(response.status).toBe(403);
});
it('an admin can look up any membership', async () => {
currentUser = { id: 'admin-1', role: 'admin' };
const response = await request(app.getHttpServer()).get('/api/teams/team-alpha/members/user-1');
expect(response.status).toBe(200);
expect(response.body).toEqual({ isMember: true });
});
});
+45 -7
View File
@@ -1,30 +1,68 @@
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
import {
Controller,
ForbiddenException,
Get,
NotFoundException,
Param,
UseGuards,
} from '@nestjs/common';
import { AuthGuard } from '../auth/auth.guard.js';
import { CurrentUser } from '../auth/current-user.decorator.js';
import { TeamsService } from './teams.service.js';
type RequestUser = { id: string; role?: string };
@Controller('api/teams')
@UseGuards(AuthGuard)
export class TeamsController {
constructor(private readonly teams: TeamsService) {}
@Get()
async list() {
return this.teams.findAll();
async list(@CurrentUser() user: RequestUser) {
if (user.role === 'admin') {
return this.teams.findAll();
}
return this.teams.findAllForUser(user.id);
}
@Get(':teamId')
async findOne(@Param('teamId') teamId: string) {
return this.teams.findById(teamId);
async findOne(@Param('teamId') teamId: string, @CurrentUser() user: RequestUser) {
return this.getAccessibleTeam(teamId, user);
}
@Get(':teamId/members')
async listMembers(@Param('teamId') teamId: string) {
async listMembers(@Param('teamId') teamId: string, @CurrentUser() user: RequestUser) {
await this.getAccessibleTeam(teamId, user);
return this.teams.listMembers(teamId);
}
@Get(':teamId/members/:userId')
async checkMembership(@Param('teamId') teamId: string, @Param('userId') userId: string) {
async checkMembership(
@Param('teamId') teamId: string,
@Param('userId') userId: string,
@CurrentUser() user: RequestUser,
) {
// A user may always ask about their own membership; anything else is
// team-scoped like the other routes.
if (userId !== user.id) {
await this.getAccessibleTeam(teamId, user);
}
const isMember = await this.teams.isMember(teamId, userId);
return { isMember };
}
/**
* Team-scoped access: admins see any team; everyone else only teams they
* are a member of. NotFoundException when the team does not exist and
* ForbiddenException when the user lacks access (same convention as the
* projects controller).
*/
private async getAccessibleTeam(teamId: string, user: RequestUser) {
const team = await this.teams.findById(teamId);
if (!team) throw new NotFoundException('Team not found');
if (user.role === 'admin') return team;
const isMember = await this.teams.isMember(teamId, user.id);
if (!isMember) throw new ForbiddenException('Not a member of this team');
return team;
}
}
+16 -1
View File
@@ -1,5 +1,5 @@
import { Inject, Injectable, Logger } from '@nestjs/common';
import { eq, and, type Db, teams, teamMembers, projects } from '@mosaicstack/db';
import { eq, and, inArray, type Db, teams, teamMembers, projects } from '@mosaicstack/db';
import { DB } from '../database/database.module.js';
@Injectable()
@@ -56,6 +56,21 @@ export class TeamsService {
return this.db.select().from(teams);
}
/**
* List only the teams the user is a member of.
*/
async findAllForUser(userId: string) {
const memberRows = await this.db
.select({ teamId: teamMembers.teamId })
.from(teamMembers)
.where(eq(teamMembers.userId, userId));
const teamIds = memberRows.map((r) => r.teamId);
if (teamIds.length === 0) return [];
return this.db.select().from(teams).where(inArray(teams.id, teamIds));
}
/**
* Find a team by ID.
*/
File diff suppressed because it is too large Load Diff