Alex is trying to open a lock whose code is a sequence that is three letters long, with each of the letters being one of $\text A$, $\text B$ or $\text C$, possibly repeated. The lock has three buttons, labeled $\text A$, $\text B$ and $\text C$. When the most recent $3$ button-presses form the code, the lock opens. What is the minimum number of total button presses Alex needs to guarantee opening the lock?
1. **Determine the total number of possible codes:**
   Each code is a sequence of three letters, and each letter can be one of $\text{A}$, $\text{B}$, or $\text{C}$. Therefore, the total number of possible codes is:
   \[
   3^3 = 27
   \]

2. **Understand the requirement for testing all codes:**
   To guarantee that Alex tests all possible codes, he needs to ensure that every possible sequence of three consecutive button presses is tested. This means that there must be at least 27 sequences of three consecutive button presses.

3. **Calculate the minimum number of button presses:**
   If Alex presses the buttons $n$ times, the number of three-letter sequences he can form is $n - 2$ (since the first sequence is formed by the 1st to 3rd presses, the second sequence by the 2nd to 4th presses, and so on, up to the $(n-2)$-th sequence formed by the $(n-2)$-th to $n$-th presses).

   To cover all 27 possible sequences, we need:
   \[
   n - 2 \geq 27
   \]
   Solving for $n$:
   \[
   n \geq 29
   \]

4. **Verify with an example sequence:**
   The sequence 
   \[
   \text{AACCACBBACABBCCCBCBABBBCAABAAA}
   \]
   is 29 letters long. We can check that it contains each of the 27 possible three-letter codes. This confirms that 29 button presses are sufficient to guarantee that all possible codes are tested.

Therefore, the minimum number of button presses required to guarantee opening the lock is $\boxed{29}$.