Commit graph

32 commits

Author SHA1 Message Date
darbs-claude
78bdebcaaa fix: add batch failure recovery to ContentService (#27)
Some checks failed
CI / PHP 8.3 (pull_request) Failing after 1m24s
CI / PHP 8.4 (pull_request) Failing after 1m27s
- Track progress in a per-batch JSON state file after each article so
  a mid-run crash leaves a recoverable checkpoint
- Add `maxRetries` parameter to generateBatch() with per-article retry
  loop (default: 1 extra attempt)
- Add `resumeBatch()` to re-process only failed/pending articles,
  skipping those already successfully generated in a prior run
- Add `loadBatchProgress()` public method for inspecting state
- State stores per-article status, attempt counts, error messages,
  and timestamps for full observability

Tests: 6 new scenarios covering state persistence, resume capability,
retry logic, and the no-state error case

Closes #27

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 11:17:56 +00:00
Claude
d88095780e
fix: use closure-based __get for mock property access
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Replace individual __get expectations with a single closure that handles
all property access. Fixes ErrorException on undefined property access
with Mockery mocks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 07:02:04 +00:00
Claude
f2f27ec766 style: fix pint code style issues
Some checks failed
CI / PHP 8.3 (push) Failing after 2m8s
CI / PHP 8.4 (push) Failing after 1m58s
2026-02-23 06:42:24 +00:00
00a7e2f4ef Merge pull request 'refactor: namespace cache keys to prevent collisions' (#50) from refactor/namespace-cache-keys into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #50
2026-02-23 06:21:34 +00:00
Claude
e0f9a87673 test: fix TestCase to use Orchestra Testbench for CI
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
2026-02-23 06:20:06 +00:00
darbs-claude
7fba0955e4 refactor: namespace cache keys to prevent collisions (closes #20)
Some checks failed
CI / PHP 8.3 (pull_request) Failing after 1m35s
CI / PHP 8.4 (pull_request) Failing after 1m31s
Replace hardcoded cache key in ForAgentsController with a config-based
key (`mcp.cache.for_agents_key`) and configurable TTL
(`mcp.cache.for_agents_ttl`). This prevents collisions with other modules
or packages that might use the same flat cache key.

- Add `cacheKey()` method on ForAgentsController, reads from config
- Add `cache` section to config.php with default key and TTL
- Dynamic Cache-Control max-age now follows the configured TTL
- Add ForAgentsControllerTest covering key customisation,
  cache storage, invalidation, TTL, and response structure

Refs: TODO.md CQ-003

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 06:18:30 +00:00
Claude
c6e52bd74c test: fix TestCase to use Orchestra Testbench for CI 2026-02-23 06:18:30 +00:00
b75b1b8191 Merge pull request 'refactor: unify ApiKeyManager to use AgentApiKey model' (#49) from refactor/api-key-manager-model into main
Some checks failed
CI / PHP 8.3 (push) Has been cancelled
CI / PHP 8.4 (push) Has been cancelled
Reviewed-on: #49
2026-02-23 06:10:45 +00:00
48547dc214 Merge pull request 'test: add job tests for BatchContentGeneration and ProcessContentTask' (#41) from test/job-tests into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #41
2026-02-23 06:09:51 +00:00
411d7decac Merge pull request 'refactor(jobs): remove processOutput stub from ProcessContentTask' (#47) from refactor/remove-process-content-task-stub into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #47
2026-02-23 06:09:22 +00:00
darbs-claude
6ebd527204 refactor: unify ApiKeyManager to use AgentApiKey model (#19)
Some checks failed
CI / PHP 8.4 (pull_request) Failing after 1m35s
CI / PHP 8.3 (pull_request) Failing after 1m46s
Switch View/Modal/Admin/ApiKeyManager.php from Core\Api\Models\ApiKey
to Core\Mod\Agentic\Models\AgentApiKey and AgentApiKeyService, bringing
the workspace-owner admin UI into consistency with all other services.

Changes:
- Replace Core\Api\Models\ApiKey import with AgentApiKey + AgentApiKeyService
- Use AgentApiKeyService::create() for key generation
- Use AgentApiKey::forWorkspace() scoping in revokeKey() and render()
- Rename newKeyScopes → newKeyPermissions, toggleScope → togglePermission
- Expose availablePermissions() from AgentApiKey for the create form
- Update blade template: permissions field, getMaskedKey(), togglePermission,
  dynamic permission checkboxes from AgentApiKey::availablePermissions()
- Add tests/Feature/ApiKeyManagerTest.php with integration coverage
- Mark CQ-002 resolved in TODO.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 06:09:05 +00:00
f97d862f27 Merge pull request 'test: add PromptVersion model tests' (#45) from test/prompt-version-tests into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #45
2026-02-23 06:08:50 +00:00
075aa05ee4 Merge pull request 'test: add AgentDetection service unit tests' (#44) from test/agent-detection-service into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #44
2026-02-23 06:08:40 +00:00
143aee7d42 Merge pull request 'test: add unit tests for HasRetry and HasStreamParsing traits' (#43) from test/service-trait-concerns into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #43
2026-02-23 06:08:25 +00:00
3c65e99727 Merge pull request 'test: add Livewire component tests for 12 admin components' (#42) from test/livewire-component-tests into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #42
2026-02-23 06:08:10 +00:00
darbs-claude
003c16c1cd refactor(jobs): remove processOutput stub from ProcessContentTask
Some checks failed
CI / PHP 8.3 (pull_request) Failing after 1m1s
CI / PHP 8.4 (pull_request) Failing after 59s
The processOutput() method was a stub with no implementation. The
ContentProcessingService dependency it accepted is from the external
host-uk/core package and its API is not available here. Content
is already persisted via markCompleted() so no output processing
was ever performed.

Removes:
- processOutput() stub method
- ContentProcessingService import and handle() parameter
- target_type/target_id guard block that called the stub

Adds unit tests covering: prompt validation, entitlement checks,
provider availability, task completion metadata, usage recording,
and template variable interpolation.

Closes #17

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 05:45:46 +00:00
darbs-claude
1abc4af519 test: add PromptVersion model tests
Some checks failed
CI / PHP 8.3 (pull_request) Failing after 56s
CI / PHP 8.4 (pull_request) Failing after 58s
Add Feature test covering PromptVersion creation, relationships (prompt,
creator), restore() rollback method, and version history tracking. Also
add idempotent migration for prompts and prompt_versions tables required
by the test suite.

Closes #15
2026-02-23 05:18:37 +00:00
Claude
3f905583a8
chore: fix pint code style and add test config
Some checks failed
CI / tests (push) Failing after 1m9s
Add phpunit.xml for standalone test execution.
Apply Laravel Pint formatting fixes across all source files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 03:50:09 +00:00
darbs-claude
964d6cdeb3 test: add AgentDetection service unit tests
Some checks failed
CI / tests (pull_request) Failing after 1m1s
Adds tests/Unit/AgentDetectionTest.php covering:
- User-Agent pattern matching for all AI providers (Anthropic, OpenAI,
  Google, Meta, Mistral) with model detection
- Browser UA detection returning notAnAgent (Chrome, Firefox, Safari, Edge)
- Non-agent bot detection (Googlebot, Bingbot, curl, python-requests, etc.)
- Edge cases: null, empty, whitespace-only, and generic programmatic UAs
- Structured MCP token parsing (provider:model:secret format)
- MCP header priority over User-Agent in HTTP requests
- Provider validation via isValidProvider() and getValidProviders()
- isAgentUserAgent() shorthand behaviour
- Each pattern documented with real-world UA examples

Closes #13

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 01:40:47 +00:00
darbs-claude
9c50d29c19 test: add unit tests for HasRetry and HasStreamParsing traits (#12)
Some checks failed
CI / tests (pull_request) Failing after 1m8s
- tests/Unit/Concerns/HasRetryTest.php: covers withRetry success paths,
  max retry limits, non-retryable 4xx errors, exponential backoff with
  sleep verification, Retry-After header, and calculateDelay formula
- tests/Unit/Concerns/HasStreamParsingTest.php: covers parseSSEStream
  (basic extraction, [DONE] termination, line-type skipping, invalid
  JSON, chunked reads) and parseJSONStream (single/multiple objects,
  nesting, escaped strings, extractor filtering, chunked reads)

Closes #12

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 01:28:07 +00:00
darbs-claude
2ba1751081 test: add Livewire component tests for all 12 admin components
Some checks failed
CI / PHP 8.2 (pull_request) Failing after 0s
CI / PHP 8.3 (pull_request) Failing after 0s
CI / PHP 8.4 (pull_request) Failing after 0s
CI / Assets (pull_request) Failing after 0s
Closes #11

Adds comprehensive Livewire tests in tests/Feature/Livewire/ covering:
- DashboardTest: stats structure, refresh action, blocked alert, quick links
- PlansTest: auth, filters, activate/complete/archive/delete actions
- PlanDetailTest: auth, plan loading, phase actions, task validation
- SessionsTest: auth, filters, pause/resume/complete/fail actions
- SessionDetailTest: auth, polling, modal states, session control
- ToolAnalyticsTest: auth, setDays, filters, success rate colour helpers
- ApiKeysTest: auth, create/edit/revoke modals, validation, stats
- ApiKeyManagerTest: workspace binding, create form, toggleScope
- ToolCallsTest: auth, filters, viewCall/closeCallDetail, badge helpers
- RequestLogTest: filters, selectRequest/closeDetail interactions
- TemplatesTest: auth, preview/import/create modals, clearFilters
- PlaygroundTest: server loading, API key validation, execute behaviour

Infrastructure:
- LivewireTestCase base class with stub view namespace registration
- HadesUser fixture for auth()->user()->isHades() checks
- Minimal stub blade views in tests/views/ (agentic and mcp namespaces)
- composer.json: add livewire/livewire and pest-plugin-livewire to
  require-dev; fix autoload-dev paths to lowercase tests/ directory

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 01:16:33 +00:00
darbs-claude
26b0f19f4c test: add job tests for BatchContentGeneration and ProcessContentTask (#10)
Some checks failed
CI / PHP 8.2 (pull_request) Failing after 1s
CI / PHP 8.3 (pull_request) Failing after 1s
CI / PHP 8.4 (pull_request) Failing after 1s
CI / Assets (pull_request) Failing after 1s
- tests/Feature/Jobs/BatchContentGenerationTest.php
  - job configuration (timeout, priority, batch size, ShouldQueue)
  - queue assignment to ai-batch with Queue::fake()
  - tag generation (batch-generation + priority:*)
  - job chaining: ProcessContentTask dispatch per task
  - handle() empty-collection path (documented alias-mock limitation)

- tests/Feature/Jobs/ProcessContentTaskTest.php
  - job configuration (tries, backoff, timeout, ShouldQueue)
  - failed() marks task failed with exception message
  - handle() early-exit: missing prompt
  - handle() early-exit: denied entitlement
  - handle() early-exit: unavailable provider
  - handle() success without workspace (no usage recording)
  - handle() success with workspace (entitlement check + usage recording)
  - processOutput() stub behaviour (target absent/present, no crash)
  - variable interpolation: strings, arrays, unmatched placeholders, empty data
  - retry logic: re-dispatch, failed() called on unhandled exception

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 00:56:16 +00:00
Snider
27d08bbe43 feat(tests): add AgenticManager tests
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 19:23:20 +00:00
Snider
9e513af049 refactor(tests): convert PlanTemplateServiceTest to Pest functional syntax
Convert PHPUnit class-based tests to Pest functional syntax with:
- 47 test cases organised into 9 describe blocks
- Proper beforeEach/afterEach hooks for test setup/teardown
- Covers: template listing, retrieval, preview, variable substitution,
  plan creation, validation, categories, context generation, edge cases
- Uses expect() assertions and method chaining for clarity

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 18:56:51 +00:00
Snider
d76db0672b refactor(tests): convert IpRestrictionServiceTest to Pest functional syntax
Rewrote all test methods to use Pest's test() function with expect()
assertions instead of PHPUnit class-based syntax:
- IP validation tests (IPv4 and IPv6)
- CIDR range matching for all prefix lengths (/0 to /32 for IPv4, /0 to /128 for IPv6)
- Whitelist management tests (parsing, formatting, comments)
- Entry validation and error handling
- Edge cases (loopback, private ranges, link-local, mixed protocols)

Test count increased from 60+ to 78 with additional edge case coverage.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 18:50:41 +00:00
Snider
e70e078bcb refactor(tests): convert AgentApiKey tests to Pest functional syntax
- Convert AgentApiKeyTest from PHPUnit class-based syntax to Pest functional syntax
- Add tests/Pest.php configuration with helper functions (createWorkspace, createApiKey)
- Organise tests using describe() blocks for better structure
- Add additional test coverage for key rotation and security edge cases
- Update TODO.md to reflect Pest syntax usage

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 18:42:56 +00:00
Snider
c432a45ca9 feat(security): switch API key to Argon2id with comprehensive tests
P2 Items Completed (P2-062 to P2-068):
- Switch AgentApiKey from SHA-256 to Argon2id hashing
- Add 200+ tests for models, services, and AI providers
- Create agent_plans migration with phases and workspace states

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 13:36:53 +00:00
Snider
a2a9423ad6 security: fix SQL injection and add workspace scoping to MCP tools
- Replace orderByRaw with parameterised CASE statements
- Add Task::scopeOrderByPriority() and scopeOrderByStatus()
- Add AgentPlan::scopeOrderByStatus()
- Add workspace validation to StateSet, StateGet, StateList tools
- Add workspace validation to PlanGet, PlanList tools
- Add SecurityTest.php with comprehensive isolation tests

Fixes SEC-002, SEC-003 from security audit.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 12:21:01 +00:00
Snider
adcc163775 refactor: update namespaces for L1/L2 package convention
- Core\Mod\Tenant -> Core\Tenant
- Core\Service\Agentic -> Core\Mod\Agentic\Service

Part of namespace restructure to align with L1/L2 module conventions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 17:34:46 +00:00
Snider
ad83825f93 refactor: rename namespace Core\Agentic to Core\Mod\Agentic
Updates all classes to use the new modular namespace convention.
Adds Service/ layer with Core\Service\Agentic for service definition.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 16:12:58 +00:00
Snider
1350472d11 monorepo sepration 2026-01-27 00:28:29 +00:00
Snider
ee7439d292
Initial commit 2026-01-26 23:20:30 +00:00