CI / Lint (PHP 8.4, phpcs, eslint) (pull_request) Successful in 1m17s
CI / Scan (secrets, workflows, shell, patterns) (pull_request) Successful in 1m58s
CI / API and MCP (PHP 8.4, MariaDB) (pull_request) Successful in 1m56s
CI / UI (playwright) (pull_request) Successful in 2m10s
CI / Security (composer and npm audit) (pull_request) Successful in 1m42s
CI / Deploy (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI / UI screenshots (before/after) (pull_request) Successful in 5m3s
Replaces lint.yml and security.yml with .gitea/workflows/ci.yml, following the shared CI standard (wiki: Infrastructure/ci-standard, modelled on Pulse and Thor). Deploys now wait for every check. Jobs: - Lint: php -l on every file and scripts/check_requirements.php under PHP 8.4 (node:22-trixie, Debian 13's packages, as on CT 132); phpcs 4.0.4 pinned with SHA-256 (was the abandoned squizlabs build, unpinned); eslint 8.57.1 from tests/lint/ (lockfile, was `npm install eslint@8`) with --max-warnings=66, today's count, so warnings can only go down. - Security: composer validate --strict, composer audit --locked --abandoned=fail, npm audit (high) and audit signatures for the test tooling. The audit found symfony/http-client advisories (fixed by the lock bump, #137) and mcp/sdk GHSA-f4rf-6ghj-mhr6, ignored with its reason in composer.json until #138 (Tinker uses neither affected middleware). - Scan: gitleaks over the full history (#134; the five findings in 527 commits were the YOUR_API_KEY placeholder on the API keys page, allowlisted for that file only in .gitleaks.toml), actionlint, shellcheck, zizmor, and semgrep with p/javascript, p/secrets and p/security-audit added to the existing packs (no new findings). - API and MCP: fresh MariaDB, migrations, seed, fixtures; then tests/api/mcp_test.php (MCP comment and link tools, 30 checks) and tests/api/test_api.py (the Bearer API contract automated reporters rely on, 132 checks: dedup by key and title, escalation, the reopen window under three Workflow Designer setups, recurrence chains, concurrent creates, lookup by dedup_key, source filter, link API). These were the local checks of #124/#131 and #121/#124. - UI and UI screenshots as before (#120). - API and UI fail on any PHP warning, notice or deprecation in the server log (tests/ci/php-warnings.sh): #130's warnings logged while every page still rendered. - Every job has a timeout; runs are grouped per ref; deploys queue and are never cancelled; the weekly run re-audits and re-scans. - Notify: Matrix alert on any failure on a deploy branch or in the weekly run, and on every deploy (was: lint failures only). tests/ui/setup.sh moves to tests/ci/setup.sh (the lint, audit and API jobs use it too) and takes WITH_DB=0 and EXTRA_PKGS. Co-Authored-By: Claude Opus 5.5 <[email protected]>
179 lines
7.9 KiB
PHP
179 lines
7.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* MCP write tools against a real database: edit_comment / delete_comment
|
|
* (permissions, hidden tickets, nested replies, audit) and link_tickets /
|
|
* unlink_tickets (normalisation, duplicates, hidden and missing tickets).
|
|
* Calls the tool classes directly as a signed-in user; the OAuth layer in
|
|
* front of them is not exercised here.
|
|
*
|
|
* tests/ui/stack.sh . 8400 tinker_ui_api # database + seed tickets 100000001-3
|
|
* php tests/api/fixtures.php /tmp/api-keys.json
|
|
* php tests/api/mcp_test.php
|
|
*
|
|
* CLI only, and only against a database whose name starts with tinker_ui.
|
|
* Needs vendor/ (composer install).
|
|
*/
|
|
|
|
if (php_sapi_name() !== 'cli') {
|
|
http_response_code(403);
|
|
exit('CLI access only');
|
|
}
|
|
|
|
$root = dirname(__DIR__, 2);
|
|
require $root . '/config/config.php';
|
|
require $root . '/vendor/autoload.php';
|
|
foreach (
|
|
[
|
|
'helpers/Database.php', 'helpers/UrlHelper.php', 'models/UserModel.php', 'models/TicketModel.php',
|
|
'models/CommentModel.php', 'models/StatsModel.php', 'services/CommentService.php',
|
|
'services/DependencyService.php', 'mcp/src/Auth/McpIdentity.php', 'mcp/src/Tools/TicketWriteTools.php',
|
|
'mcp/src/ToolCatalog.php',
|
|
] as $file
|
|
) {
|
|
require_once "$root/$file";
|
|
}
|
|
|
|
use TinkerTickets\Mcp\Auth\McpIdentity;
|
|
use TinkerTickets\Mcp\Tools\TicketWriteTools;
|
|
use TinkerTickets\Mcp\ToolCatalog;
|
|
|
|
if (!str_starts_with((string)($GLOBALS['config']['DB_NAME'] ?? ''), 'tinker_ui')) {
|
|
fwrite(STDERR, "refusing: the configured database must start with tinker_ui\n");
|
|
exit(2);
|
|
}
|
|
|
|
$conn = Database::getConnection();
|
|
$users = new UserModel($conn);
|
|
$as = function (string $username) use ($users): void {
|
|
McpIdentity::set($users->getUserByUsername($username), ['tickets:write']);
|
|
};
|
|
$tools = new TicketWriteTools($conn);
|
|
$pass = 0;
|
|
$fail = 0;
|
|
$check = function (string $name, bool $ok, $detail = '') use (&$pass, &$fail): void {
|
|
$ok ? $pass++ : $fail++;
|
|
echo ($ok ? 'PASS ' : 'FAIL ') . $name . ($ok ? '' : ' ' . json_encode($detail)) . "\n";
|
|
};
|
|
$err = function (callable $fn): ?string {
|
|
try {
|
|
$fn();
|
|
return null;
|
|
} catch (\Mcp\Exception\ToolCallException $e) {
|
|
return $e->getMessage();
|
|
}
|
|
};
|
|
$row = fn(int $id) => $conn->query(
|
|
"SELECT comment_text, markdown_enabled FROM ticket_comments WHERE comment_id = $id"
|
|
)->fetch_assoc();
|
|
$audit = fn(string $action, int $id) => $conn->query(
|
|
"SELECT details FROM audit_log WHERE action_type = '$action' AND entity_type = 'comment'
|
|
AND entity_id = '$id' ORDER BY audit_id DESC LIMIT 1"
|
|
)->fetch_assoc();
|
|
|
|
echo "== comments\n";
|
|
$check('edit_comment is a write tool', ToolCatalog::isWriteTool('edit_comment'));
|
|
$check('delete_comment is a write tool', ToolCatalog::isWriteTool('delete_comment'));
|
|
|
|
// Edit own comment
|
|
$as('alice');
|
|
$a = $tools->addComment('100000001', 'first draft', true)['comment_id'];
|
|
$r = $tools->editComment($a, " **final** text ", false);
|
|
$check('alice edits her comment', $r === ['comment_id' => $a, 'ticket_id' => '100000001', 'edited' => true], $r);
|
|
$check(
|
|
'text trimmed and stored, markdown off',
|
|
$row($a) === ['comment_text' => '**final** text', 'markdown_enabled' => '0'],
|
|
$row($a)
|
|
);
|
|
$check('edit is audit-logged', str_contains($audit('update', $a)['details'] ?? '', '100000001'), $audit('update', $a));
|
|
$e = $err(fn() => $tools->editComment($a, ' '));
|
|
$check('empty text rejected', $e === 'Comment text cannot be empty', $e);
|
|
$e = $err(fn() => $tools->editComment(999999, 'x'));
|
|
$check('missing comment: not found', $e === 'Comment 999999 not found', $e);
|
|
|
|
// Someone else's comment
|
|
$as('bob');
|
|
$e = $err(fn() => $tools->editComment($a, 'hijack'));
|
|
$check('bob cannot edit alice\'s comment', $e === 'You do not have permission to edit this comment', $e);
|
|
$e = $err(fn() => $tools->deleteComment($a));
|
|
$check('bob cannot delete alice\'s comment', $e === 'You do not have permission to delete this comment', $e);
|
|
$check('alice\'s text unchanged', $row($a)['comment_text'] === '**final** text', $row($a));
|
|
|
|
// A comment on a ticket alice can't see reads as not found
|
|
$as('ci.tester');
|
|
$c = $tools->addComment('100000009', 'confidential note')['comment_id'];
|
|
$as('alice');
|
|
$e = $err(fn() => $tools->editComment($c, 'peek'));
|
|
$check('hidden ticket: edit says not found', $e === "Comment $c not found", $e);
|
|
$e = $err(fn() => $tools->deleteComment($c));
|
|
$check('hidden ticket: delete says not found', $e === "Comment $c not found", $e);
|
|
$check('hidden comment untouched', $row($c)['comment_text'] === 'confidential note', $row($c));
|
|
|
|
// An admin can edit anyone's comment, including a system comment with no user_id
|
|
$as('ci.tester');
|
|
$sys = (int)$conn->query("SELECT comment_id FROM ticket_comments WHERE user_id IS NULL LIMIT 1")->fetch_row()[0];
|
|
$r = $tools->editComment($sys, 'edited by admin');
|
|
$check('admin edits a system comment', $r['edited'] === true && $row($sys)['comment_text'] === 'edited by admin', $r);
|
|
$as('alice');
|
|
$e = $err(fn() => $tools->editComment($sys, 'x'));
|
|
$check('alice cannot edit a system comment', $e === 'You do not have permission to edit this comment', $e);
|
|
|
|
// Delete with nested replies
|
|
$as('bob');
|
|
$r1 = $tools->addComment('100000001', 'reply 1', true, $a)['comment_id'];
|
|
$as('alice');
|
|
$r2 = $tools->addComment('100000001', 'reply 2', true, $r1)['comment_id'];
|
|
$r = $tools->deleteComment($a);
|
|
$check(
|
|
'alice deletes her comment, 2 replies go with it',
|
|
$r === ['comment_id' => $a, 'ticket_id' => '100000001', 'deleted' => true, 'replies_removed' => 2],
|
|
$r
|
|
);
|
|
$check('comment and replies gone', $row($a) === null && $row($r1) === null && $row($r2) === null);
|
|
$check(
|
|
'delete audit has replies_removed',
|
|
str_contains($audit('delete', $a)['details'] ?? '', '"replies_removed":2'),
|
|
$audit('delete', $a)
|
|
);
|
|
$e = $err(fn() => $tools->deleteComment($a));
|
|
$check('deleting again: not found', $e === "Comment $a not found", $e);
|
|
$as('ci.tester');
|
|
$tools->deleteComment($c);
|
|
|
|
echo "== links\n";
|
|
$conn->query(
|
|
"DELETE FROM ticket_dependencies WHERE ticket_id IN ('100000001','100000002','100000003')
|
|
OR depends_on_id IN ('100000001','100000002','100000003')"
|
|
);
|
|
$as('alice');
|
|
$r = $tools->linkTickets('100000001', 'Blocks', ' 100000002 ');
|
|
$check(
|
|
'link (relation case and id spaces normalised)',
|
|
$r === ['ticket_id' => '100000001', 'relation' => 'blocks', 'other_ticket_id' => '100000002'],
|
|
$r
|
|
);
|
|
$e = $err(fn() => $tools->linkTickets('100000001', 'blocks', '100000002'));
|
|
$check('duplicate link refused', $e !== null, $e);
|
|
$e = $err(fn() => $tools->linkTickets('100000002', 'blocked_by', '100000001'));
|
|
$check('inverse of an existing link refused', $e !== null, $e);
|
|
$e = $err(fn() => $tools->linkTickets('100000001', 'causes', '100000002'));
|
|
$check('bad relation message', $e === 'relation must be one of: blocks, blocked_by, relates_to, duplicates', $e);
|
|
$e = $err(fn() => $tools->linkTickets('100000001', 'relates_to', '100000001'));
|
|
$check('self link message', $e === 'A ticket cannot be linked to itself', $e);
|
|
$e = $err(fn() => $tools->linkTickets('abc', 'relates_to', '100000001'));
|
|
$check('non-digit id: not found', $e === 'Ticket abc not found', $e);
|
|
$e = $err(fn() => $tools->linkTickets('100000001', 'relates_to', '100000009'));
|
|
$check('hidden target: not found', $e === 'Ticket 100000009 not found', $e);
|
|
$e = $err(fn() => $tools->linkTickets('999999998', 'relates_to', '100000001'));
|
|
$check('missing source: not found', $e === 'Ticket 999999998 not found', $e);
|
|
$r = $tools->unlinkTickets('100000002', 'blocked_by', '100000001');
|
|
$check('unlink stated from the other side', $r['removed'] === true, $r);
|
|
$e = $err(fn() => $tools->unlinkTickets('100000001', 'blocks', '100000002'));
|
|
$check('unlink again: no such link', $e === 'No blocks link between 100000001 and 100000002', $e);
|
|
$tools->linkTickets('100000003', 'duplicates', '100000001');
|
|
$r = $tools->unlinkTickets('100000003', 'duplicates', '100000001');
|
|
$check('duplicates link unlinks (one-way relation)', $r['removed'] === true, $r);
|
|
|
|
echo "\n$pass passed, $fail failed\n";
|
|
exit($fail || !$pass ? 1 : 0);
|