MC/website/integrations/osticket/tests/dev-jarvis-policy.test.php
2026-11-27 23:43:05 +00:00

40 lines
6.2 KiB
PHP

<?php
require dirname(__DIR__).'/dev-policy.php';
$checks=0;
function check($condition,$message){global $checks;$checks++;if(!$condition)throw new RuntimeException($message);}
function valid_request(){return ['title'=>'A clear staff request','workflow'=>'existing','type'=>'Operations','system'=>'Account service','environment'=>'test','action_id'=>'clan.clear-protected-rosters','targets'=>'The two fixed protected institutions','objective'=>'Perform the approved scoped operation.','current'=>'The current roster is populated.','expected'=>'Only the approved target roster changes.','acceptance'=>'Verify the exact result and audit receipt.','scope'=>'Only the selected action and its fixed targets.','preserve'=>'All unrelated clans, balances and votes.','priority'=>'Medium','privacy'=>'1','jarvis_values'=>['ticketId'=>'DR_DEV-0000098','reference'=>'Owner-approved example']];}
function invalid_request($input,$message){[$v,$e]=dune_dev_validate($input);check(count($e)>0,$message);return $v;}
[$v,$e]=dune_dev_validate(valid_request());check(!$e,'Existing action rejected: '.implode('; ',$e));
check($v['execution_state']==='requested','Submission must not claim execution');
check(json_decode($v['action_parameters'],true)['ticketId']==='DR_DEV-0000098','Typed action parameters missing');
check($v['action_template_version']===1,'Action version not pinned');
check(str_contains(dune_dev_execution_brief($v),'Do not write code or direct SQL'),'Existing action lost the execution route');
$q=valid_request();$q['action_id']='dev.issue';invalid_request($q,'Web developer issuance accepted');
$q=valid_request();$q['jarvis_values']['sql']='DELETE';invalid_request($q,'Unknown action parameter accepted');
$q=valid_request();unset($q['jarvis_values']['ticketId']);invalid_request($q,'Required typed field not checked');
$q=valid_request();$q['jarvis_values']['reference']=['bad'];invalid_request($q,'Nested action value accepted');
$q=valid_request();$q['action_id']='xp.correct';$q['jarvis_values']=['ticketId'=>'DR_DEV-0000098','recipient'=>'Example','amountXP'=>'50','caseReference'=>'Approved example'];[$v,$e]=dune_dev_validate($q);check(!$e,'Typed number rejected');check(json_decode($v['action_parameters'],true)['amountXP']===50,'Number was not typed');
$q['jarvis_values']['amountXP']='1e9';invalid_request($q,'Non-integer notation accepted');
$q=valid_request();$q['workflow']='idea';$q['environment']='proposal';unset($q['jarvis_values']);$q['action_id']='';[$v,$e]=dune_dev_validate($q);check(!$e,'Future idea requires technical catalogue knowledge');check(str_contains($v['catalogue_review'],'Not yet reviewed'),'Unknown catalogue status fabricated a completed review');check(str_contains(dune_dev_execution_brief($v),'feature proposal'),'Idea classified as an execution');
$q['workflow']='capability';invalid_request($q,'Missing new-action proposal accepted');$q['missing_capability']='A key that enables a proposed scoped staff task.';[$v,$e]=dune_dev_validate($q);check(!$e,'Plain-language new key proposal rejected');
$q=valid_request();$q['workflow']='devkey';$q['action_id']='';unset($q['jarvis_values']);$q+=['catalogue_review'=>'No normal scoped action supports the approved maintenance request.','dev_actor'=>'Reviewed developer account','dev_actions'=>'Review the exact approved manifest and target records.','dev_expiry'=>'10','destructive_actions'=>'None','risk'=>'Validate recovery and preserve unrelated records.','dev_acknowledgement'=>'1'];[$v,$e]=dune_dev_validate($q);check(!$e,'Complete devkey request rejected: '.implode('; ',$e));check($v['action_id']===''&&$v['action_parameters']==='{}','Developer request inherited ordinary action parameters');check(str_contains(dune_dev_prompt($v),'DEV KEY REQUEST'),'Developer intent absent from ticket');check(str_contains(dune_dev_execution_brief($v),'server/CLI-only'),'Developer boundary omitted');
foreach(['0','16','1e1']as$expiry){$bad=$q;$bad['dev_expiry']=$expiry;invalid_request($bad,'Invalid dev lifetime accepted');}
$bad=$q;unset($bad['dev_acknowledgement']);invalid_request($bad,'Developer review acknowledgement omitted');
$bad=$q;$bad['environment']='proposal';invalid_request($bad,'Developer request without concrete environment accepted');
$bad=valid_request();$bad['dev_actions']='Unexpected developer operation';invalid_request($bad,'Hidden developer operation accepted on ordinary route');
$bad=valid_request();$bad['privacy']='0';invalid_request($bad,'Privacy confirmation omitted');
$bad=valid_request();$bad['execution_state']='completed';[$v,$e]=dune_dev_validate($bad);check(!$e&&$v['execution_state']==='requested','Client overrode execution state');
check(str_contains(dune_dev_execution_brief(['objective'=>'Old request']),'Legacy request'),'Legacy ticket was reinterpreted as an executable instruction');
$original=['title'=>'Old title','objective'=>'Original request'];$copy=$original;dune_dev_execution_brief($original);check($original===$copy,'Legacy request data mutated');
$owner=['username'=>'unimatrix999','ranks'=>['owners']];check(dune_dev_owner($owner),'Existing owner approval changed');check(!dune_dev_owner(['username'=>'unimatrix999','ranks'=>['user']]),'Name alone gained owner authority');
check(str_contains(dune_dev_execution_brief($v),'Language: use English'),'English execution requirement missing');
$dev=['username'=>'dev','ranks'=>['network_admin']];
check(dune_dev_team($dev)&&dune_dev_submitter($dev)&&dune_dev_priority_editor($dev),'Current Dev account cannot read/write Dev requests');
check(dune_dev_transition($dev,'complete','approved','Verified completion evidence attached.')==='completed','Dev cannot close approved work');
check(!dune_dev_owner($dev),'Dev gained owner approval authority');
check(!dune_dev_priority_editor(['username'=>'dev','ranks'=>['user']]),'Dev name alone grants editing');
check(!dune_dev_priority_editor(['username'=>'other','ranks'=>['network_admin']]),'Unrelated account gained Dev editing');
$managed=['username'=>'dev','nativePermissionManagement'=>false,'permissions'=>['web.tickets.dev'],'ranks'=>['user']];
check(dune_dev_priority_editor($managed),'Managed Dev permission was ignored');
$managed['permissions']=[];check(!dune_dev_priority_editor($managed),'Removed Dev permission still allows editing');
echo json_encode(['passed'=>$checks,'failed'=>0,'ticket_created'=>false,'keys_issued'=>0])."\n";