File size: 1,316 Bytes
caf8059
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Explicit local-validation scope. This does not authorize human acceptance or deployment."""
from src.modules.skill.domain.models import SkillError, digest


class LocalValidation:
    def __init__(self, runtime, actor, authorization_ref):
        if not authorization_ref or len(authorization_ref) > 300:
            raise ValueError('AUTHORIZATION_REFERENCE_REQUIRED')
        self.runtime, self.actor, self.authorization_ref = runtime, actor, authorization_ref

    def step(self, run_id):
        run = self.runtime.get(self.actor, run_id)
        if (run['release'].get('publication_scope') != 'local-validation-only'
                or run['release'].get('authorization_ref') != self.authorization_ref):
            raise SkillError('VALIDATION_SCOPE_REQUIRED', '自动验证只接受本地验证版本。', 403)
        if run['status'] == 'queued':
            return self.runtime.advance(self.actor, run_id)
        if run['status'] == 'repair_required':
            return self.runtime.repair(self.actor, run_id)
        if run['status'] == 'waiting_approval' and run['pending_approval']['scope'] in {'design', 'execution'}:
            pending = run['pending_approval']
            return self.runtime.approve(self.actor, run_id, pending['digest'], delegation=self.authorization_ref)
        return run