XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESystem

【Rust】XFE系统,基于Rust和汇编

公开
关注 0 Fork 0 Star 0
UTF-8
"""Offline negative controls for native terminal readback; never guest acceptance."""
import copy
import unittest

from TestBoot import terminal_command_output


def snapshot(command='cat CliProof/Command.txt', output='NativeTerminalReady'):
    prompt = 'X:\\Users\\Default\\Documents> '
    return {'WindowId': 4, 'Busy': False, 'Input': '', 'LastCommand': command,
            'Prompt': prompt, 'Version': '0.3.0-dev.3',
            'Text': prompt + 'write CliProof/Command.txt NativeTerminalReady\n' + prompt + command + '\n' + output + '   \n  \n'}


class IndependentTerminalEvidenceTests(unittest.TestCase):
    def test_cd_echo_uses_the_observed_pre_command_prompt(self):
        item=snapshot('cd /Disks/NVMe0P1','');before=item['Prompt'];item['Prompt']='X:\\Disks\\NVMe0P1> '
        self.assertEqual([],terminal_command_output(item,item['LastCommand'],before))
        with self.assertRaises(AssertionError):terminal_command_output(item,item['LastCommand'])
        with self.assertRaises(AssertionError):terminal_command_output(item,item['LastCommand'],'X:\\Wrong> ')
    def test_exact_post_cat_output_is_separate_from_write_history_arguments(self):
        self.assertEqual(['NativeTerminalReady'], terminal_command_output(snapshot(), 'cat CliProof/Command.txt'))
        empty = snapshot(output='')
        self.assertEqual([], terminal_command_output(empty, 'cat CliProof/Command.txt'))
        self.assertNotIn('NativeTerminalReady', terminal_command_output(empty, 'cat CliProof/Command.txt'))

    def test_latest_echo_of_repeated_command_owns_its_output(self):
        item = snapshot(); item['Text'] += item['Prompt'] + item['LastCommand'] + '\nactual latest body\n'
        self.assertEqual(['actual latest body'], terminal_command_output(item, item['LastCommand']))

    def test_busy_unsubmitted_wrong_command_and_missing_prompt_never_qualify(self):
        for field, value in (('Busy', True), ('Input', 'cat file'), ('LastCommand', 'write file NativeTerminalReady'),
                             ('Prompt', ''), ('Version', ''), ('Text', 'NativeTerminalReady\n')):
            item = snapshot(); item[field] = value
            with self.subTest(field=field), self.assertRaises(AssertionError):
                terminal_command_output(item, 'cat CliProof/Command.txt')

    def test_real_command_errors_are_rejected_without_hiding_old_success(self):
        for error in ('Error: File not found.', 'Unknown command: cat. Type help.'):
            item = snapshot(output=error)
            with self.subTest(error=error), self.assertRaises(AssertionError):
                terminal_command_output(item, 'cat CliProof/Command.txt')

    def test_edited_echo_requires_both_exact_command_and_its_actual_own_output(self):
        item = snapshot('echo abd', 'abd')
        self.assertEqual(['abd'], terminal_command_output(item, 'echo abd'))
        wrong = copy.deepcopy(item); wrong['Text'] = item['Prompt'] + 'echo abc\nabc\n'
        with self.assertRaises(AssertionError): terminal_command_output(wrong, 'echo abd')
        wrong = copy.deepcopy(item); wrong['Text'] = item['Prompt'] + 'echo abd\nabc\n'
        self.assertNotIn('abd', terminal_command_output(wrong, 'echo abd'))


if __name__ == '__main__':
    unittest.main()