Implement plans

This commit is contained in:
2026-03-04 02:19:22 +00:00
parent 34ee49410d
commit 0718a06c19
31 changed files with 3987 additions and 181 deletions

View File

@@ -9,8 +9,10 @@ from core.messaging.reply_sync import extract_reply_ref, resolve_reply_target
from core.views.compose import _command_options_for_channel
from core.models import (
ChatSession,
CommandAction,
CommandChannelBinding,
CommandProfile,
CommandVariantPolicy,
Message,
Person,
PersonIdentifier,
@@ -313,4 +315,124 @@ class Phase1CommandEngineTests(TestCase):
self.assertIn("bp", names)
self.assertIn("bp set", names)
self.assertIn("bp set range", names)
self.assertIn("codex", names)
self.assertNotIn("announce task ids", names)
def test_first_user_codex_command_auto_enables_defaults_for_channel(self):
CommandProfile.objects.filter(user=self.user, slug="codex").delete()
msg = Message.objects.create(
user=self.user,
session=self.session,
sender_uuid="",
custom_author="USER",
text="#codex status#",
ts=6000,
source_service="web",
source_chat_id="web-chan-2",
message_meta={},
)
results = async_to_sync(process_inbound_message)(
CommandContext(
service="web",
channel_identifier="web-chan-2",
message_id=str(msg.id),
user_id=self.user.id,
message_text="#codex status#",
payload={},
)
)
self.assertEqual(1, len(results))
self.assertTrue(results[0].ok)
profile = CommandProfile.objects.filter(user=self.user, slug="codex").first()
self.assertIsNotNone(profile)
self.assertTrue(bool(profile.enabled if profile else False))
ingress_exists = CommandChannelBinding.objects.filter(
profile=profile,
direction="ingress",
enabled=True,
service="signal",
channel_identifier="+15550000002",
).exists()
egress_exists = CommandChannelBinding.objects.filter(
profile=profile,
direction="egress",
enabled=True,
service="signal",
channel_identifier="+15550000002",
).exists()
self.assertTrue(ingress_exists)
self.assertTrue(egress_exists)
def test_first_user_bp_command_auto_setup_is_idempotent(self):
CommandProfile.objects.filter(user=self.user, slug="bp").delete()
msg1 = Message.objects.create(
user=self.user,
session=self.session,
sender_uuid="",
custom_author="USER",
text="#bp#",
ts=7000,
source_service="web",
source_chat_id="web-chan-3",
message_meta={},
)
first_results = async_to_sync(process_inbound_message)(
CommandContext(
service="web",
channel_identifier="web-chan-3",
message_id=str(msg1.id),
user_id=self.user.id,
message_text="#bp#",
payload={},
)
)
self.assertEqual(1, len(first_results))
self.assertEqual("reply_required", first_results[0].error)
profile = CommandProfile.objects.filter(user=self.user, slug="bp").first()
self.assertIsNotNone(profile)
if profile is None:
return
self.assertEqual(3, CommandAction.objects.filter(profile=profile).count())
self.assertEqual(3, CommandVariantPolicy.objects.filter(profile=profile).count())
self.assertEqual(
2,
CommandChannelBinding.objects.filter(
profile=profile,
service="signal",
channel_identifier="+15550000002",
).count(),
)
msg2 = Message.objects.create(
user=self.user,
session=self.session,
sender_uuid="",
custom_author="USER",
text="#bp#",
ts=8000,
source_service="web",
source_chat_id="web-chan-3",
message_meta={},
)
second_results = async_to_sync(process_inbound_message)(
CommandContext(
service="web",
channel_identifier="web-chan-3",
message_id=str(msg2.id),
user_id=self.user.id,
message_text="#bp#",
payload={},
)
)
self.assertEqual(1, len(second_results))
self.assertEqual("reply_required", second_results[0].error)
self.assertEqual(3, CommandAction.objects.filter(profile=profile).count())
self.assertEqual(3, CommandVariantPolicy.objects.filter(profile=profile).count())
self.assertEqual(
2,
CommandChannelBinding.objects.filter(
profile=profile,
service="signal",
channel_identifier="+15550000002",
).count(),
)