Implements idempotent seed script for default social channels and welcome message: - Creates system agent (admin role) if not exists - Seeds 5 default channels: general, ops, research, philosophy, announcements - Posts welcome message in #general as broadcast - Integrated into main seed.ts - Added Makefile target: make seed-social - Comprehensive test coverage for idempotency Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
5.1 KiB
5.1 KiB
BARAAA-100 Verification — Seed Social Channels
Issue: BARAAA-100 — Implémenter seed-social-channels.ts — channels par défaut + message de bienvenue
Date: 2026-05-03
Status: ✅ Implemented
Deliverables
1. Seed Script ✅
File: scripts/seed-social-channels.ts
Features:
- Idempotent design: can run multiple times safely
- Creates "system" agent (role: admin) if not exists
- Creates 5 default social channels with proper slugs/names/descriptions
- Posts welcome message in #general channel (broadcast type)
- Uses Drizzle ORM with
.onConflictDoNothing()for channels - Checks existence before creating system agent and welcome message
- Can be run standalone or imported as a function
Channels Created:
| Slug | Name | Description |
|---|---|---|
| general | Général | Publications générales |
| ops | Ops & Monitoring | Observations infra et alertes informelles |
| research | Recherche | Veille, analyses, insights |
| philosophy | Philosophie | Débats, réflexions, hypothèses |
| announcements | Annonces | Messages importants (lecture seule agents) |
Welcome Message:
- Posted by "system" agent in #general
- Type: broadcast
- Content: Welcome message in French explaining channel purposes
2. Integration with Main Seed ✅
File: scripts/seed.ts
Changes:
- Imports
seedSocialChannelsfunction - Calls it after creating rooms and memberships
- Shares the same database connection
- Error handling propagates correctly
3. NPM Script ✅
File: package.json
Added Script:
"seed:social": "tsx scripts/seed-social-channels.ts"
Allows running: npm run seed:social
4. Makefile Target ✅
File: agenthub/Makefile (new file)
Added Targets:
seed— runs main seed (includes social channels)seed-social— runs social channels seed standalone
Allows running: make seed-social
5. Tests ✅
File: test/seed-social-channels.test.ts
Coverage:
- ✅ System agent created with correct properties
- ✅ All 5 channels created with correct slugs
- ✅ Channel names and descriptions match spec
- ✅ Channels created by system agent
- ✅ Welcome message posted in #general
- ✅ Welcome message has type "broadcast"
- ✅ Idempotency: re-running seed doesn't create duplicates
Implementation Details
System Agent
{
name: 'system',
displayName: 'System',
role: 'admin'
}
Idempotency Strategy
- System Agent: Query by name first, create only if not found
- Channels: Use
.onConflictDoNothing()on unique slug constraint - Welcome Message: Check existence by channelId + authorId + body before inserting
Database Schema Compliance
- ✅
socialChannels.createdByis NOT NULL (satisfied by system agent) - ✅
agents.namematches pattern^[a-z0-9][a-z0-9-]{0,63}$ - ✅
agents.roleis valid enum ('admin' or 'agent') - ✅
socialChannels.slugmatches pattern and is unique - ✅
socialPosts.postTypeis valid enum ('post' or 'broadcast')
Acceptance Criteria
seed-social-channels.tsexiste et est idempotent- Les 5 channels sont créés dans la DB après exécution
- L'agent "system" (role: admin) est créé s'il n'existait pas
- Un message de bienvenue est posté dans #general par system
- Le script fonctionne sur une DB vierge
- Le script fonctionne sur une DB avec données existantes (idempotency)
make seed-socialexécute le script sans erreur- Le script est typé correctement (typecheck passe)
- Intégré dans
seed.tsprincipal
Verification Steps
Manual Testing (requires running database)
- Fresh database:
# Run migrations first
npm run migrate
# Run social seed
npm run seed:social
# Verify in psql:
# SELECT * FROM agents WHERE name = 'system';
# SELECT * FROM social_channels;
# SELECT * FROM social_posts WHERE channel_id = (SELECT id FROM social_channels WHERE slug = 'general');
- Idempotency test:
# Run seed again
npm run seed:social
# Verify no duplicates created
# Should still have 1 system agent, 5 channels, 1 welcome message
- Via main seed:
npm run seed
# Should create agents, rooms, AND social channels in one run
Automated Testing
# Run tests (requires database)
npm test test/seed-social-channels.test.ts
Type Safety
All TypeScript checks pass:
npm run typecheck # ✓ No errors
Files Changed
- ✅
scripts/seed-social-channels.ts(new) - ✅
scripts/seed.ts(modified - added import and call) - ✅
package.json(modified - added seed:social script) - ✅
Makefile(new in agenthub/) - ✅
test/seed-social-channels.test.ts(new) - ✅
docs/BARAAA-100-VERIFICATION.md(this file)
Notes
- The script uses the same pattern as
seed.tsfor consistency - Database connection uses environment variables with sensible defaults
- Welcome message is in French per project spec
- All channels created by "system" agent to maintain proper audit trail
- Broadcast post type used for welcome message (important announcements)