context_drop 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +74 -1
  3. data/app/assets/javascripts/context_drop/context_drop.js +152 -11
  4. data/app/controllers/context_drop/application_controller.rb +12 -0
  5. data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +38 -0
  6. data/app/controllers/context_drop/dashboard/integrations_controller.rb +140 -0
  7. data/app/controllers/context_drop/feedbacks_controller.rb +38 -14
  8. data/app/controllers/context_drop/mcp_events_controller.rb +66 -0
  9. data/app/helpers/context_drop/dashboard_helper.rb +6 -0
  10. data/app/javascript/context_drop/__tests__/widget.test.ts +229 -18
  11. data/app/javascript/context_drop/styles.ts +16 -0
  12. data/app/javascript/context_drop/widget.ts +136 -11
  13. data/app/models/context_drop/event_occurrence.rb +34 -0
  14. data/app/models/context_drop/mcp_event_subscription.rb +25 -0
  15. data/app/models/context_drop/notification_destination.rb +84 -0
  16. data/app/views/context_drop/dashboard/feedbacks/show.html.erb +8 -10
  17. data/app/views/context_drop/dashboard/integrations/_form.html.erb +92 -0
  18. data/app/views/context_drop/dashboard/integrations/edit.html.erb +13 -0
  19. data/app/views/context_drop/dashboard/integrations/index.html.erb +101 -0
  20. data/app/views/context_drop/dashboard/integrations/new.html.erb +13 -0
  21. data/app/views/layouts/context_drop/application.html.erb +78 -0
  22. data/config/routes.rb +5 -0
  23. data/db/migrate/20261124000001_create_context_drop_events_and_notifications.rb +47 -0
  24. data/lib/context_drop/feedback_events/publisher.rb +100 -0
  25. data/lib/context_drop/mcp/dispatcher.rb +20 -5
  26. data/lib/context_drop/mcp/event_stream_registry.rb +34 -0
  27. data/lib/context_drop/mcp/events.rb +178 -0
  28. data/lib/context_drop/notification_secrets.rb +85 -0
  29. data/lib/context_drop/notifications/deliverer.rb +49 -0
  30. data/lib/context_drop/notifications/lark_client.rb +140 -0
  31. data/lib/context_drop/notifications/webhook_client.rb +103 -0
  32. data/lib/context_drop/version.rb +1 -1
  33. data/lib/context_drop.rb +5 -0
  34. metadata +21 -4
@@ -54,6 +54,7 @@ module ContextDrop
54
54
  end
55
55
 
56
56
  feedback = nil
57
+ previous_status = nil
57
58
 
58
59
  ContextDrop::Feedback.transaction do
59
60
  sanitized_meta = ContextDrop::MetadataSanitizer.sanitize_feedback_metadata(payload["metadata"])
@@ -126,7 +127,11 @@ module ContextDrop
126
127
  return if performed?
127
128
 
128
129
  feedback.reload
129
- invoke_lifecycle_callback(:on_feedback_created, feedback)
130
+ invoke_lifecycle_callback(
131
+ :on_feedback_created,
132
+ feedback,
133
+ dashboard_url: feedback_dashboard_url(feedback)
134
+ )
130
135
  ownership_token = ContextDrop::OwnershipToken.generate(feedback.id)
131
136
 
132
137
  render json: {
@@ -144,6 +149,7 @@ module ContextDrop
144
149
 
145
150
  def update
146
151
  feedback = ContextDrop::Feedback.includes(:element_references, :attachments, comments: :attachments).find_by(id: params[:id])
152
+ previous_status = feedback&.status
147
153
  if feedback.nil? || feedback.deleted?
148
154
  render json: { error: "Feedback not found" }, status: :not_found
149
155
  return
@@ -323,7 +329,12 @@ module ContextDrop
323
329
  return if performed?
324
330
 
325
331
  feedback.reload
326
- invoke_lifecycle_callback(:on_feedback_updated, feedback)
332
+ invoke_lifecycle_callback(
333
+ :on_feedback_updated,
334
+ feedback,
335
+ previous_status: previous_status,
336
+ dashboard_url: feedback_dashboard_url(feedback)
337
+ )
327
338
 
328
339
  raw_tokens = combined_raw_ownership_tokens(payload["ownership_token"])
329
340
  ownership_token = ContextDrop::OwnershipToken.find_token_for(raw_tokens, feedback.id) ||
@@ -357,7 +368,11 @@ module ContextDrop
357
368
  end
358
369
 
359
370
  feedback.soft_delete!
360
- invoke_lifecycle_callback(:on_feedback_deleted, feedback)
371
+ invoke_lifecycle_callback(
372
+ :on_feedback_deleted,
373
+ feedback,
374
+ dashboard_url: feedback_dashboard_url(feedback)
375
+ )
361
376
 
362
377
  render json: {
363
378
  id: feedback.id,
@@ -387,6 +402,8 @@ module ContextDrop
387
402
  return
388
403
  end
389
404
 
405
+ previous_status = feedback.status
406
+
390
407
  submitter = current_context_drop_submitter
391
408
  author_label = if submitter
392
409
  if submitter.respond_to?(:name) && submitter.name.present?
@@ -451,7 +468,12 @@ module ContextDrop
451
468
  return if performed?
452
469
 
453
470
  feedback.reload
454
- invoke_lifecycle_callback(:on_feedback_updated, feedback)
471
+ invoke_lifecycle_callback(
472
+ :on_feedback_updated,
473
+ feedback,
474
+ previous_status: previous_status,
475
+ dashboard_url: feedback_dashboard_url(feedback)
476
+ )
455
477
 
456
478
  raw_tokens = combined_raw_ownership_tokens(payload["ownership_token"])
457
479
  ownership_token = ContextDrop::OwnershipToken.find_token_for(raw_tokens, feedback.id) ||
@@ -480,17 +502,9 @@ module ContextDrop
480
502
  end
481
503
 
482
504
  att = ContextDrop::Attachment.where(feedback_id: feedback.id).find_by(id: params[:id])
483
- if att.nil? || !att.respond_to?(:file) || !att.file.attached?
505
+ if att.nil? || !stream_context_drop_attachment!(att)
484
506
  head :not_found
485
- return
486
507
  end
487
-
488
- response.set_header("Cache-Control", "private, max-age=3600")
489
- response.set_header("Content-Security-Policy", "default-src 'none'; sandbox")
490
- send_data att.file.download,
491
- type: att.file.content_type || "image/png",
492
- disposition: "inline",
493
- filename: att.file.filename.to_s
494
508
  end
495
509
 
496
510
  private
@@ -715,15 +729,25 @@ module ContextDrop
715
729
  raise ContextDrop::UploadValidator::ValidationError, "Invalid base64 attachment data"
716
730
  end
717
731
 
718
- def invoke_lifecycle_callback(hook_name, feedback)
732
+ def invoke_lifecycle_callback(hook_name, feedback, **context)
719
733
  return unless ContextDrop.config.respond_to?(hook_name)
720
734
 
721
735
  callback = ContextDrop.config.public_send(hook_name)
722
736
  callback.call(feedback) if callback.respond_to?(:call)
737
+ ContextDrop::FeedbackEvents::Publisher.map_lifecycle_callback(hook_name, feedback, **context)
723
738
  rescue StandardError => e
724
739
  Rails.logger.error("[ContextDrop] #{hook_name} callback error: #{e.class}: #{e.message}") if defined?(Rails.logger) && Rails.logger
725
740
  end
726
741
 
742
+ def feedback_dashboard_url(feedback)
743
+ path = "/context_drop/dashboard/feedbacks/#{feedback.id}"
744
+ if respond_to?(:request) && request&.base_url.present?
745
+ "#{request.base_url}#{path}"
746
+ else
747
+ path
748
+ end
749
+ end
750
+
727
751
  def stringify_hash(obj)
728
752
  if obj.respond_to?(:to_unsafe_h)
729
753
  obj.to_unsafe_h.transform_keys(&:to_s)
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module ContextDrop
6
+ class McpEventsController < ApplicationController
7
+ skip_before_action :verify_authenticity_token
8
+ skip_before_action :ensure_context_drop_enabled!
9
+
10
+ before_action :ensure_mcp_enabled!
11
+ before_action :authenticate_mcp_request!
12
+ include ActionController::Live
13
+
14
+ def stream
15
+ response.headers["Content-Type"] = "text/event-stream"
16
+ response.headers["Cache-Control"] = "no-cache"
17
+ response.headers["X-Accel-Buffering"] = "no"
18
+
19
+ queue = Queue.new
20
+ ContextDrop::MCP::EventStreamRegistry.subscribe(queue)
21
+
22
+ response.stream.write("event: ready\ndata: {}\n\n")
23
+
24
+ loop do
25
+ payload = queue.pop
26
+ response.stream.write("event: mcp-event\ndata: #{JSON.generate(payload)}\n\n")
27
+ end
28
+ rescue IOError, ActionController::Live::ClientDisconnected
29
+ nil
30
+ ensure
31
+ ContextDrop::MCP::EventStreamRegistry.unsubscribe(queue) if queue
32
+ response.stream.close
33
+ end
34
+
35
+ private
36
+
37
+ def ensure_mcp_enabled!
38
+ return if ContextDrop.config.mcp_enabled
39
+
40
+ head :not_found
41
+ end
42
+
43
+ def authenticate_mcp_request!
44
+ if ContextDrop.config.authorize_mcp.respond_to?(:call)
45
+ return if ContextDrop.config.authorize_mcp.call(self)
46
+
47
+ head :unauthorized
48
+ return
49
+ end
50
+
51
+ expected_key = ContextDrop.config.mcp_api_key.to_s
52
+ if expected_key.strip.empty?
53
+ head :unauthorized
54
+ return
55
+ end
56
+
57
+ auth_header = request.headers["Authorization"].to_s
58
+ provided_token = auth_header.start_with?("Bearer ") ? auth_header.sub(/\ABearer\s+/i, "").strip : ""
59
+
60
+ unless provided_token.bytesize == expected_key.bytesize &&
61
+ ActiveSupport::SecurityUtils.secure_compare(provided_token, expected_key)
62
+ head :unauthorized
63
+ end
64
+ end
65
+ end
66
+ end
@@ -70,6 +70,12 @@ module ContextDrop
70
70
  def cd_icon_comment(size: 13)
71
71
  %(<svg width="#{size}" height="#{size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"></path></svg>).html_safe
72
72
  end
73
+
74
+ # Serve binaries through the mounted engine (not host Active Storage URLs) so
75
+ # screenshots work when the host app uses a relative URL root or proxies storage.
76
+ def cd_dashboard_attachment_path(attachment)
77
+ attachment_dashboard_feedback_path(attachment.feedback_id, attachment_id: attachment.id)
78
+ end
73
79
  end
74
80
  end
75
81
 
@@ -487,20 +487,22 @@ class MockDomElement {
487
487
  public parentNode: MockDomElement | null = null;
488
488
  public childNodes: MockDomElement[] = [];
489
489
  public hidden: boolean = false;
490
- public type: string = "";
491
490
  public title: string = "";
492
491
  public textContent: string = "";
493
492
  public placeholder: string = "";
494
493
  public value: string = "";
495
494
  public disabled: boolean = false;
496
495
  public selected: boolean = false;
497
- public autocomplete: string = "";
496
+ public noValidate: boolean = false;
497
+ public spellcheck: boolean = true;
498
498
  public multiple: boolean = false;
499
499
  public accept: string = "";
500
500
  public src: string = "";
501
501
  public alt: string = "";
502
502
  public scrollTop: number = 0;
503
503
  public scrollHeight: number = 0;
504
+ private _type: string = "";
505
+ private _autocomplete: string = "";
504
506
  private rawHtml: string = "";
505
507
  private attrs: Map<string, string> = new Map();
506
508
  private listeners: Map<string, MockListenerEntry[]> = new Map();
@@ -543,10 +545,39 @@ class MockDomElement {
543
545
  }
544
546
  }
545
547
 
548
+ public get type(): string {
549
+ return this._type;
550
+ }
551
+
552
+ public set type(val: string) {
553
+ this._type = val;
554
+ this.attrs.set("type", val);
555
+ }
556
+
557
+ public get autocomplete(): string {
558
+ return this._autocomplete;
559
+ }
560
+
561
+ public set autocomplete(val: string) {
562
+ this._autocomplete = val;
563
+ this.attrs.set("autocomplete", val);
564
+ }
565
+
566
+ public get form(): MockDomElement | null {
567
+ if (["INPUT", "TEXTAREA", "SELECT", "BUTTON"].includes(this.tagName)) {
568
+ return this.closest("form");
569
+ }
570
+ return null;
571
+ }
572
+
546
573
  public setAttribute(name: string, value: string): void {
547
574
  this.attrs.set(name, value);
548
575
  if (name === "class") {
549
576
  this.classList.syncFromString(value);
577
+ } else if (name === "type") {
578
+ this._type = value;
579
+ } else if (name === "autocomplete") {
580
+ this._autocomplete = value;
550
581
  }
551
582
  }
552
583
 
@@ -567,12 +598,32 @@ class MockDomElement {
567
598
  }
568
599
 
569
600
  public appendChild(child: MockDomElement): MockDomElement {
601
+ if (child.parentNode && child.parentNode !== this) {
602
+ child.parentNode.removeChild(child);
603
+ }
570
604
  child.parentElement = this;
571
605
  child.parentNode = this;
572
606
  this.childNodes.push(child);
573
607
  return child;
574
608
  }
575
609
 
610
+ public insertBefore(newChild: MockDomElement, refChild: MockDomElement | null): MockDomElement {
611
+ if (!refChild) {
612
+ return this.appendChild(newChild);
613
+ }
614
+ const idx = this.childNodes.indexOf(refChild);
615
+ if (idx === -1) {
616
+ return this.appendChild(newChild);
617
+ }
618
+ if (newChild.parentNode) {
619
+ newChild.parentNode.removeChild(newChild);
620
+ }
621
+ newChild.parentElement = this;
622
+ newChild.parentNode = this;
623
+ this.childNodes.splice(idx, 0, newChild);
624
+ return newChild;
625
+ }
626
+
576
627
  public removeChild(child: MockDomElement): MockDomElement {
577
628
  const idx = this.childNodes.indexOf(child);
578
629
  if (idx !== -1) {
@@ -593,18 +644,52 @@ class MockDomElement {
593
644
  }
594
645
 
595
646
  public matches(selector: string): boolean {
596
- if (selector.startsWith(".")) {
597
- return this.classList.contains(selector.slice(1));
647
+ if (selector.includes(",")) {
648
+ return selector
649
+ .split(",")
650
+ .map((part) => part.trim())
651
+ .filter(Boolean)
652
+ .some((part) => this.matchesSingleSelector(part));
598
653
  }
599
- if (selector.startsWith("#")) {
600
- return this.getAttribute("id") === selector.slice(1);
654
+ return this.matchesSingleSelector(selector.trim());
655
+ }
656
+
657
+ private matchesSingleSelector(sel: string): boolean {
658
+ if (!sel) return false;
659
+ let rest = sel;
660
+
661
+ const tagMatch = rest.match(/^[a-zA-Z][a-zA-Z0-9_-]*/);
662
+ if (tagMatch) {
663
+ if (this.tagName.toLowerCase() !== tagMatch[0].toLowerCase()) return false;
664
+ rest = rest.slice(tagMatch[0].length);
601
665
  }
602
- const attrMatch = selector.match(/^\[([a-zA-Z0-9_-]+)(?:=['"]([^'"]*)['"])?\]$/);
603
- if (attrMatch) {
604
- if (!this.hasAttribute(attrMatch[1])) return false;
605
- return attrMatch[2] === undefined || this.getAttribute(attrMatch[1]) === attrMatch[2];
666
+
667
+ while (rest.length > 0) {
668
+ if (rest.startsWith(".")) {
669
+ const clsMatch = rest.match(/^\.([a-zA-Z0-9_-]+)/);
670
+ if (!clsMatch) return false;
671
+ if (!this.classList.contains(clsMatch[1])) return false;
672
+ rest = rest.slice(clsMatch[0].length);
673
+ } else if (rest.startsWith("#")) {
674
+ const idMatch = rest.match(/^#([a-zA-Z0-9_-]+)/);
675
+ if (!idMatch) return false;
676
+ if (this.getAttribute("id") !== idMatch[1]) return false;
677
+ rest = rest.slice(idMatch[0].length);
678
+ } else if (rest.startsWith("[")) {
679
+ const attrMatch = rest.match(/^\[([a-zA-Z0-9_-]+)(?:(\^=|=)['"]?([^'"\]]*)['"]?)?\]/);
680
+ if (!attrMatch) return false;
681
+ const [, attrName, op, expected] = attrMatch;
682
+ if (!this.hasAttribute(attrName)) return false;
683
+ const actual = this.getAttribute(attrName) ?? "";
684
+ if (op === "=" && actual !== expected) return false;
685
+ if (op === "^=" && !actual.startsWith(expected)) return false;
686
+ rest = rest.slice(attrMatch[0].length);
687
+ } else {
688
+ return false;
689
+ }
606
690
  }
607
- return this.tagName.toLowerCase() === selector.toLowerCase();
691
+
692
+ return true;
608
693
  }
609
694
 
610
695
  public closest(selector: string): MockDomElement | null {
@@ -625,6 +710,20 @@ class MockDomElement {
625
710
  return null;
626
711
  }
627
712
 
713
+ public querySelectorAll(selector: string): MockDomElement[] {
714
+ const results: MockDomElement[] = [];
715
+ const walk = (node: MockDomElement): void => {
716
+ for (const child of node.childNodes) {
717
+ if (child.matches(selector)) {
718
+ results.push(child);
719
+ }
720
+ walk(child);
721
+ }
722
+ };
723
+ walk(this);
724
+ return results;
725
+ }
726
+
628
727
  public getBoundingClientRect(): {
629
728
  x: number;
630
729
  y: number;
@@ -824,11 +923,11 @@ describe("ContextDrop v0.2 Book-Corner Peel-to-Pin & Agentic Sidebar", () => {
824
923
  const sidebar = shadowRoot.querySelector(".cd-agent-sidebar");
825
924
  const compactBar = shadowRoot.querySelector(".cd-compact-bar");
826
925
 
827
- assert.ok(bookCorner && composer && sidebar && compactBar);
926
+ assert.ok(bookCorner && composer && compactBar);
927
+ assert.equal(sidebar, null, "Agent sidebar must not mount when agent.enabled is false");
828
928
  assert.equal(bookCorner.hidden, false);
829
929
  assert.equal(bookCorner.classList.contains("corner-bottom_right"), true);
830
930
  assert.equal(composer.hidden, true);
831
- assert.equal(sidebar.hidden, true);
832
931
  assert.equal(compactBar.hidden, true);
833
932
 
834
933
  // Pointer click without drag opens normal floating feedback composer
@@ -1582,11 +1681,12 @@ describe("ContextDrop v0.2 Book-Corner Peel-to-Pin & Agentic Sidebar", () => {
1582
1681
  async ({ widget, shadowRoot }) => {
1583
1682
  const bookCorner = shadowRoot.querySelector(".cd-book-corner");
1584
1683
  const composer = shadowRoot.querySelector(".cd-composer");
1585
- const sidebar = shadowRoot.querySelector(".cd-agent-sidebar");
1586
1684
  const modeSwitch = composer ? composer.querySelector(".cd-composer-mode-switch-wrap") : null;
1587
- assert.ok(bookCorner && composer && sidebar && modeSwitch);
1685
+ assert.ok(bookCorner && composer && modeSwitch);
1588
1686
 
1589
- // When agent is disabled for local development:
1687
+ // When agent is disabled, no agent sidebar or BYOK drawer exists in shadowRoot:
1688
+ assert.equal(shadowRoot.querySelector(".cd-agent-sidebar"), null);
1689
+ assert.equal(shadowRoot.querySelector(".cd-byok-drawer"), null);
1590
1690
  assert.equal(widget.isAgentModeActive(), false);
1591
1691
  assert.equal(widget.isSmartSelectionMode(), false); // verbose mode
1592
1692
  assert.equal(modeSwitch.hidden, true);
@@ -1594,13 +1694,20 @@ describe("ContextDrop v0.2 Book-Corner Peel-to-Pin & Agentic Sidebar", () => {
1594
1694
  // Clicking the book corner opens the floating verbose composer
1595
1695
  bookCorner.dispatchEvent(new MockUiEvent("click"));
1596
1696
  assert.equal(composer.hidden, false);
1597
- assert.equal(sidebar.hidden, true);
1697
+ assert.equal(shadowRoot.querySelector(".cd-agent-sidebar"), null);
1598
1698
 
1599
- // Opting into agent enables agent mode
1699
+ // Opting into agent dynamically mounts sidebar and enables agent mode
1600
1700
  widget.setWidgetConfig({ agent: { enabled: true } });
1701
+ const sidebar = shadowRoot.querySelector(".cd-agent-sidebar");
1702
+ assert.ok(sidebar);
1601
1703
  assert.equal(widget.isAgentModeActive(), true);
1602
1704
  assert.equal(sidebar.hidden, false);
1603
1705
  assert.equal(composer.hidden, true);
1706
+
1707
+ // Disabling agent again unmounts the sidebar cleanly
1708
+ widget.setWidgetConfig({ agent: { enabled: false } });
1709
+ assert.equal(shadowRoot.querySelector(".cd-agent-sidebar"), null);
1710
+ assert.equal(shadowRoot.querySelector(".cd-byok-drawer"), null);
1604
1711
  },
1605
1712
  {
1606
1713
  "data-config": JSON.stringify({
@@ -1613,6 +1720,110 @@ describe("ContextDrop v0.2 Book-Corner Peel-to-Pin & Agentic Sidebar", () => {
1613
1720
  );
1614
1721
  });
1615
1722
 
1723
+ it("does not mount .cd-agent-sidebar, .cd-byok-drawer, or input[type='password'] when agent.enabled is false", async () => {
1724
+ await withMountedWidget(
1725
+ ({ shadowRoot }) => {
1726
+ assert.equal(shadowRoot.querySelector(".cd-agent-sidebar"), null);
1727
+ assert.equal(shadowRoot.querySelector(".cd-byok-drawer"), null);
1728
+ assert.equal(shadowRoot.querySelector('input[type="password"]'), null);
1729
+ assert.equal(shadowRoot.querySelector("[aria-label='Provider API Key']"), null);
1730
+
1731
+ // Even feedback composer controls must have an owning <form autocomplete="off"> so nothing leaks into Chromium's synthetic unowned form
1732
+ const controls = shadowRoot.querySelectorAll("input, textarea, select");
1733
+ assert.ok(controls.length >= 2, "Expected composer file input and textarea");
1734
+ for (const control of controls) {
1735
+ assert.notEqual(
1736
+ control.form,
1737
+ null,
1738
+ `Expected <${control.tagName.toLowerCase()}> to have an owning <form>`
1739
+ );
1740
+ assert.equal(control.form?.getAttribute("autocomplete"), "off");
1741
+ }
1742
+ },
1743
+ {
1744
+ "data-config": JSON.stringify({
1745
+ enabled: true,
1746
+ environment: "production",
1747
+ position: "bottom_right",
1748
+ agent: { enabled: false }
1749
+ })
1750
+ }
1751
+ );
1752
+ });
1753
+
1754
+ it("wraps all shadowRoot form controls in <form autocomplete='off'> and avoids input[type='password'] when agent.enabled is true", async () => {
1755
+ await withMountedWidget(
1756
+ ({ shadowRoot }) => {
1757
+ const sidebar = shadowRoot.querySelector(".cd-agent-sidebar");
1758
+ const byokDrawer = shadowRoot.querySelector(".cd-byok-drawer");
1759
+ const byokBtn = shadowRoot.querySelector("[aria-label='Open BYOK API key settings']");
1760
+ const keyInput = shadowRoot.querySelector("[aria-label='Provider API Key']");
1761
+ assert.ok(sidebar && byokDrawer && byokBtn && keyInput);
1762
+
1763
+ // Never mounts any <input type="password"> (uses CSS-masked type="text" instead)
1764
+ assert.equal(shadowRoot.querySelector('input[type="password"]'), null);
1765
+ assert.equal(keyInput.type, "text");
1766
+ assert.equal(keyInput.getAttribute("type"), "text");
1767
+ assert.equal(keyInput.classList.contains("is-masked-secret"), true);
1768
+ assert.equal(keyInput.disabled, true, "BYOK key input stays disabled while drawer is closed");
1769
+
1770
+ // Verify stylesheet masks .cd-input.is-masked-secret with -webkit-text-security: disc
1771
+ const styleEl = shadowRoot.querySelector("style");
1772
+ assert.ok(styleEl);
1773
+ assert.equal(styleEl.textContent.includes("-webkit-text-security: disc"), true);
1774
+
1775
+ // Opening BYOK drawer enables keyInput while still keeping zero input[type="password"]
1776
+ byokBtn.dispatchEvent(new MockUiEvent("click"));
1777
+ assert.equal(byokDrawer.hidden, false);
1778
+ assert.equal(keyInput.disabled, false);
1779
+ assert.equal(shadowRoot.querySelector('input[type="password"]'), null);
1780
+
1781
+ // Every BYOK control has explicit autofill & password-manager extension ignore attributes
1782
+ const byokControls = byokDrawer.querySelectorAll("input, select");
1783
+ assert.equal(byokControls.length, 5);
1784
+ for (const byokCtrl of byokControls) {
1785
+ assert.equal(byokCtrl.getAttribute("autocomplete"), "off");
1786
+ assert.equal(byokCtrl.getAttribute("spellcheck"), "false");
1787
+ assert.equal(byokCtrl.getAttribute("data-1p-ignore"), "true");
1788
+ assert.equal(byokCtrl.getAttribute("data-lpignore"), "true");
1789
+ assert.equal(byokCtrl.getAttribute("data-bwignore"), "true");
1790
+ assert.equal(byokCtrl.getAttribute("data-form-type"), "other");
1791
+ }
1792
+
1793
+ // Every <input>, <textarea>, and <select> across shadowRoot has an owning <form autocomplete="off">
1794
+ const allControls = shadowRoot.querySelectorAll("input, textarea, select");
1795
+ assert.equal(allControls.length, 8);
1796
+ for (const control of allControls) {
1797
+ assert.notEqual(
1798
+ control.form,
1799
+ null,
1800
+ `Expected <${control.tagName.toLowerCase()}> (${control.getAttribute("aria-label") || control.type}) to be owned by a <form>`
1801
+ );
1802
+ assert.equal(control.form?.getAttribute("autocomplete"), "off");
1803
+ assert.notEqual(control.type, "password");
1804
+ }
1805
+
1806
+ // Every owning <form> prevents default navigation on submit
1807
+ const forms = shadowRoot.querySelectorAll("form");
1808
+ assert.ok(forms.length >= 3);
1809
+ for (const form of forms) {
1810
+ assert.equal(form.getAttribute("autocomplete"), "off");
1811
+ const submitEv = new MockUiEvent("submit");
1812
+ form.dispatchEvent(submitEv);
1813
+ assert.equal(submitEv.defaultPrevented, true);
1814
+ }
1815
+ },
1816
+ {
1817
+ "data-config": JSON.stringify({
1818
+ enabled: true,
1819
+ environment: "development",
1820
+ position: "bottom_right",
1821
+ agent: { enabled: true }
1822
+ })
1823
+ }
1824
+ );
1825
+ });
1826
+
1616
1827
  it("loads own feedbacks on open, edits message + context inline with draft restoration, and emits context-drop:update", async () => {
1617
1828
  const g = globalThis as Record<string, unknown>;
1618
1829
  const prevFetch = g.fetch;
@@ -173,6 +173,13 @@ export const WIDGET_SHADOW_STYLES = `
173
173
  box-sizing: border-box;
174
174
  }
175
175
 
176
+ .cd-form-shell {
177
+ display: contents;
178
+ margin: 0;
179
+ padding: 0;
180
+ border: 0;
181
+ }
182
+
176
183
  ::selection {
177
184
  background: var(--cd-pin-soft);
178
185
  color: var(--cd-ink);
@@ -1500,6 +1507,15 @@ select:focus-visible {
1500
1507
  font-size: 11.5px;
1501
1508
  }
1502
1509
 
1510
+ .cd-input.is-masked-secret {
1511
+ -webkit-text-security: disc;
1512
+ }
1513
+
1514
+ .cd-input.is-masked-secret:placeholder-shown,
1515
+ .cd-input.is-masked-secret:disabled {
1516
+ -webkit-text-security: none;
1517
+ }
1518
+
1503
1519
  .cd-drawer-actions {
1504
1520
  display: flex;
1505
1521
  align-items: center;